📄 packet.hh
字号:
Packet::prev() const{#if CLICK_LINUXMODULE return (Packet *)(skb()->prev);#else return _prev;#endif}inline Packet *&Packet::prev(){#if CLICK_LINUXMODULE return (Packet *&)(skb()->prev);#else return _prev;#endif}inline voidPacket::set_prev(Packet *p){#if CLICK_LINUXMODULE skb()->prev = p->skb();#else _prev = p;#endif}/** @brief Return true iff the packet's MAC header pointer is set. * @sa set_mac_header, clear_mac_header */inline boolPacket::has_mac_header() const{#if CLICK_LINUXMODULE# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) return skb_mac_header_was_set(skb());# else return skb()->mac.raw != 0;# endif#else return _mac != 0;#endif}/** @brief Return the packet's MAC header pointer. * @warning Not useful if !has_mac_header(). * @sa ether_header, set_mac_header, clear_mac_header, mac_header_length, * mac_length */inline const unsigned char *Packet::mac_header() const{#if CLICK_LINUXMODULE# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) return skb_mac_header(skb());# else return skb()->mac.raw;# endif#else return _mac;#endif}/** @brief Return true iff the packet's network header pointer is set. * @sa set_network_header, clear_network_header */inline boolPacket::has_network_header() const{#if CLICK_LINUXMODULE# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)# if NET_SKBUFF_DATA_USES_OFFSET return skb()->network_header != ~0U;# else return skb()->network_header != 0;# endif# else return skb()->nh.raw != 0;# endif#else return _nh != 0;#endif}/** @brief Return the packet's network header pointer. * @warning Not useful if !has_network_header(). * @sa ip_header, ip6_header, set_network_header, clear_network_header, * network_header_length, network_length */inline const unsigned char *Packet::network_header() const{#if CLICK_LINUXMODULE# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) return skb_network_header(skb());# else return skb()->nh.raw;# endif#else return _nh;#endif}/** @brief Return true iff the packet's network header pointer is set. * @sa set_network_header, clear_transport_header */inline boolPacket::has_transport_header() const{#if CLICK_LINUXMODULE# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)# if NET_SKBUFF_DATA_USES_OFFSET return skb()->transport_header != ~0U;# else return skb()->transport_header != 0;# endif# else return skb()->h.raw != 0;# endif#else return _h != 0;#endif}/** @brief Return the packet's transport header pointer. * @warning Not useful if !has_transport_header(). * @sa tcp_header, udp_header, icmp_header, set_transport_header, * clear_transport_header, transport_length */inline const unsigned char *Packet::transport_header() const{#if CLICK_LINUXMODULE# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) return skb_transport_header(skb());# else return skb()->h.raw;# endif#else return _h;#endif}/** @brief Return the packet's MAC header pointer as Ethernet. * @invariant (void *) ether_header() == (void *) mac_header() * @warning Not useful if !has_mac_header(). * @sa mac_header */inline const click_ether *Packet::ether_header() const{ return reinterpret_cast<const click_ether *>(mac_header());}/** @brief Return the packet's network header pointer as IPv4. * @invariant (void *) ip_header() == (void *) network_header() * @warning Not useful if !has_network_header(). * @sa network_header */inline const click_ip *Packet::ip_header() const{ return reinterpret_cast<const click_ip *>(network_header());}/** @brief Return the packet's network header pointer as IPv6. * @invariant (void *) ip6_header() == (void *) network_header() * @warning Not useful if !has_network_header(). * @sa network_header */inline const click_ip6 *Packet::ip6_header() const{ return reinterpret_cast<const click_ip6 *>(network_header());}/** @brief Return the packet's transport header pointer as ICMP. * @invariant (void *) icmp_header() == (void *) transport_header() * @warning Not useful if !has_transport_header(). * @sa transport_header */inline const click_icmp *Packet::icmp_header() const{ return reinterpret_cast<const click_icmp *>(transport_header());}/** @brief Return the packet's transport header pointer as TCP. * @invariant (void *) tcp_header() == (void *) transport_header() * @warning Not useful if !has_transport_header(). * @sa transport_header */inline const click_tcp *Packet::tcp_header() const{ return reinterpret_cast<const click_tcp *>(transport_header());}/** @brief Return the packet's transport header pointer as UDP. * @invariant (void *) udp_header() == (void *) transport_header() * @warning Not useful if !has_transport_header(). * @sa transport_header */inline const click_udp *Packet::udp_header() const{ return reinterpret_cast<const click_udp *>(transport_header());}/** @brief Return the packet's length starting from its MAC header pointer. * @invariant mac_length() == end_data() - mac_header() * @warning Not useful if !has_mac_header(). */inline intPacket::mac_length() const{ return end_data() - mac_header();}/** @brief Return the packet's length starting from its network header pointer. * @invariant network_length() == end_data() - network_header() * @warning Not useful if !has_network_header(). */inline intPacket::network_length() const{ return end_data() - network_header();}/** @brief Return the packet's length starting from its transport header pointer. * @invariant transport_length() == end_data() - transport_header() * @warning Not useful if !has_transport_header(). */inline intPacket::transport_length() const{ return end_data() - transport_header();}inline const Timestamp &Packet::timestamp_anno() const{#if CLICK_LINUXMODULE# if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 13) return *reinterpret_cast<const Timestamp *>(&skb()->stamp);# else return *reinterpret_cast<const Timestamp *>(&skb()->tstamp);# endif#else return _timestamp;#endif}inline Timestamp &Packet::timestamp_anno(){#if CLICK_LINUXMODULE# if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 13) return *reinterpret_cast<Timestamp *>(&skb()->stamp);# else return *reinterpret_cast<Timestamp *>(&skb()->tstamp);# endif#else return _timestamp;#endif}inline voidPacket::set_timestamp_anno(const Timestamp ×tamp){ timestamp_anno() = timestamp;}inline net_device *Packet::device_anno() const{#if CLICK_LINUXMODULE return skb()->dev;#elif CLICK_BSDMODULE if (m()) return m()->m_pkthdr.rcvif; else return 0;#else return 0;#endif}inline voidPacket::set_device_anno(net_device *dev){#if CLICK_LINUXMODULE skb()->dev = dev;#elif CLICK_BSDMODULE if (m()) m()->m_pkthdr.rcvif = dev;#else (void) dev;#endif}inline Packet::PacketTypePacket::packet_type_anno() const{#if CLICK_LINUXMODULE return (PacketType)(skb()->pkt_type & PACKET_TYPE_MASK);#else return _pkt_type;#endif}inline voidPacket::set_packet_type_anno(PacketType p){#if CLICK_LINUXMODULE skb()->pkt_type = (skb()->pkt_type & PACKET_CLEAN) | p;#else _pkt_type = p;#endif}/** @brief Create and return a new packet. * @param data data to be copied into the new packet * @param length length of packet * @return new packet, or null if no packet could be created * * The @a data is copied into the new packet. If @a data is null, the * packet's data is left uninitialized. The new packet's headroom equals * @link Packet::default_headroom default_headroom @endlink, its tailroom is 0. * * The returned packet's annotations are cleared and its header pointers are * null. */inline WritablePacket *Packet::make(const void *data, uint32_t length){ return make(default_headroom, data, length, 0);}/** @brief Create and return a new packet. * @param length length of packet * @return new packet, or null if no packet could be created * * The packet's data is left uninitialized. The new packet's headroom equals * @link Packet::default_headroom default_headroom @endlink, its tailroom is 0. * * The returned packet's annotations are cleared and its header pointers are * null. */inline WritablePacket *Packet::make(uint32_t length){ return make(default_headroom, (const unsigned char *) 0, length, 0);}#if CLICK_LINUXMODULE/** @brief Change an sk_buff into a Packet (linuxmodule). * @param skb input sk_buff * @return the packet * * In the Linux kernel module, Packet objects are sk_buff objects. This * function simply changes an sk_buff into a Packet by claiming its @a skb * argument. If <tt>skb->users</tt> is 1, then @a skb is orphaned by * <tt>skb_orphan(skb)</tt> and returned. If it is larger than 1, then @a skb * is cloned and the clone is returned. (sk_buffs used for Click Packet * objects must have <tt>skb->users</tt> == 1.) Null might be returned if * there's no memory for the clone. * * The returned packet's annotations and header pointers <em>are not * cleared</em>: they have the same values they did in the sk_buff. If the * packet came from Linux, then the header pointers and shared annotations * (timestamp, packet type, next/prev packet) might have valid values, but the * Click annotations (address, user) likely do not. Use clear_annotations() * to clear them. */inline Packet *Packet::make(struct sk_buff *skb){ if (atomic_read(&skb->users) == 1) { skb_orphan(skb); return reinterpret_cast<Packet *>(skb); } else { Packet *p = reinterpret_cast<Packet *>(skb_clone(skb, GFP_ATOMIC)); atomic_dec(&skb->users); return p; }}#endif/** @brief Delete this packet. * * The packet header (including annotations) is destroyed and its memory * returned to the system. The packet's data is also freed if this is the * last clone. */inline voidPacket::kill(){#if CLICK_LINUXMODULE struct sk_buff *b = skb(); b->next = b->prev = 0;# if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 15) b->list = 0;# endif skbmgr_recycle_skbs(b);#else if (_use_count.dec_and_test()) delete this;#endif}#if CLICK_BSDMODULE /* BSD kernel module */inline voidPacket::assimilate_mbuf(Packet *p){ struct mbuf *m = p->m(); if (!m) return; p->_head = (unsigned char *) (m->m_flags & M_EXT ? m->m_ext.ext_buf : m->m_flags & M_PKTHDR ? m->m_pktdat : m->m_dat); p->_data = (unsigned char *)m->m_data; p->_tail = (unsigned char *)(m->m_data + m->m_len); p->_end = p->_head + ( m->m_flags & M_EXT ? MCLBYTES : m->m_flags & M_PKTHDR ? MHLEN : MLEN);}inline voidPacket::assimilate_mbuf(){ assimilate_mbuf(this);}inline Packet *Packet::make(struct mbuf *m){ if (!(m->m_flags & M_PKTHDR)) panic("trying to construct Packet from a non-packet mbuf"); Packet *p = new Packet; if (m->m_pkthdr.len != m->m_len) { /* click needs contiguous data */ // click_chatter("m_pulldown, Click needs contiguous data");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -