📄 aggregateip.hh
字号:
// -*- c-basic-offset: 4 -*-#ifndef CLICK_AGGREGATEIP_HH#define CLICK_AGGREGATEIP_HH#include <click/element.hh>#include "elements/ip/ipfieldinfo.hh"CLICK_DECLS/*=cAggregateIP(FIELD, I<KEYWORDS>)=s analysis, IPsets aggregate annotation based on IP packet field=dAggregateIP sets the aggregate annotation on every passing packet to a portionof that packet's IP header, transport header, or payload, depending on thevalue of the FIELD argument.FIELD can be the name of a header field, like C<"ip tos">, or a generaloffset-length specification, like C<"ip[8:2]">. Either form can be modifiedwith a mask, such as C<"ip src/8"> or C<"ip[8:2] & 0x3F0">.The aggregate annotation value uses host byte order.Valid header field names are C<"ip vers">, C<"ip hl">, C<"ip tos">, C<"ipdscp">, C<"ip ecn">, C<"ip len">, C<"ip id">, C<"ip off"> (the entirefragmentation offset field), C<"ip rf">, C<"ip df">, C<"ip mf">, C<"ipfragoff"> (just the fragmentation offset value, without the RF, DF, and MFbits), C<"ip ttl">, C<"ip proto">, C<"ip sum">, C<"ip src">, C<"ip dst">,C<"udp sport">, C<"udp dport">, C<"udp len">, C<"udp sum">, C<"tcp sport">,C<"tcp dport">, C<"tcp seq">, C<"tcp ack">, C<"tcp hl">, C<"tcp flags">,C<"tcp fin">, C<"tcp syn">, C<"tcp rst">, C<"tcp psh">, C<"tcp ackf">, C<"tcpurg">, C<"tcp win">, C<"tcp sum">, C<"tcp urp">, C<"icmp type">, C<"icmpcode">, and C<"icmp sum">.General offset-length specifications begin with C<"ip">, C<"transp">, orC<"data">, depending on whether the offset should be measured relative to theIP header, transport header, or payload. (The names C<"tcp">, C<"udp">, andC<"icmp"> act like C<"transp">, but enforce the specified IP protocol.) Nextcomes the offset and length, which can take several forms:=over 8=item C<[OFFSET:LENGTH]>The LENGTH bytes starting at byte OFFSET.=item C<[OFFSET1-OFFSET2]>From byte OFFSET1 to byte OFFSET2, inclusive.=item C<[OFFSET]>The single byte at OFFSET.=item C<{OFFSET:LENGTH}>, C<{OFFSET1-OFFSET2}>, C<{OFFSET}>Similar, but OFFSETs and LENGTHs are measured in bits.=backFinally, the mask can equal either `C</NUM>', which means take the top NUMbits of the field, or `C<& MASK>', which means bitwise-and the field withMASK. (MASK must contain exactly one set of contiguous 1 bits.)Keyword arguments are:=over 8=item INCREMENTALBoolean. If true, then incrementally update the aggregate annotation: given afield N bits wide with value V, and an old aggregate annotation of O, the newaggregate annotation will equal (O * 2^N) + V. Default is false.=item UNSHIFT_IP_ADDRBoolean. If true, and the aggregated field lies within either the IP source ordestination address, then set the aggregate annotation to the masked portionof that address without shifting. For example, consider a packet with sourceaddress 1.0.0.0, and aggregate field C<"ip src/8">. Without UNSHIFT_IP_ADDR,the packet will get aggregate annotation 1; with UNSHIFT_IP_ADDR, it will getaggregate annotation 16777216. Default is false.=back=nPackets lacking the specified field are pushed onto output 1, or dropped ifthere is no output 1. A packet may lack a field because it is too short, it isa fragment, or it has the wrong protocol. (C<"tcp sport">, for example, isrelevant only for first-fragment TCP packets; C<"data"> specifications workonly for first-fragment TCP and UDP.)The simple specifications C<"sport"> and C<"dport"> (no C<"ip">, C<"tcp">, orC<"udp">) apply to either TCP or UDP packets.=eHere are a bunch of equivalent ways to ask for the top 8 bits of the IP sourceaddress: AggregateIP(ip src/8) AggregateIP(ip src & 0xFF000000) AggregateIP(ip[12]) AggregateIP("ip[12, 1]") // protect comma AggregateIP("ip{96, 8}") AggregateIP(ip{96-103})=h header read-onlyReturns the header type AggregateIP is using: either "ip", "transp", or"payload".=h bit_offset read-onlyReturns the offset into the header of the start of the aggregated field, inbits.=h bit_length read-onlyReturns the length of the aggregated field, in bits.=aAggregateLength, AggregateFlows, AggregateCounter*/class AggregateIP : public Element { public: AggregateIP(); ~AggregateIP(); const char *class_name() const { return "AggregateIP"; } void notify_noutputs(int); const char *processing() const { return "a/ah"; } int configure(Vector<String> &, ErrorHandler *); void add_handlers(); void push(int, Packet *); Packet *pull(int); private: uint32_t _offset; uint32_t _shift; uint32_t _mask; bool _incremental; bool _unshift_ip_addr; IPField _f; Packet *handle_packet(Packet *); Packet *bad_packet(Packet *); static String read_handler(Element *, void *); };CLICK_ENDDECLS#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -