5#include <click/glue.hh>
7#include <click/packet_anno.hh>
9#include "flow/common.hh"
11# include <click/skbmgr.hh>
12#elif CLICK_PACKET_USE_DPDK || HAVE_DPDK
13# include <rte_debug.h>
15# include <rte_malloc.h>
16# include <click/dpdk_glue.hh>
18#if CLICK_PACKET_USE_DPDK
19#define DPDK_ANNO_SIZE sizeof(Packet::AllAnno)
20#elif CLICK_PACKET_INSIDE_DPDK
21#define DPDK_ANNO_SIZE (((sizeof(Packet) - 1) / 4) +1) * 4
23#define DPDK_ANNO_SIZE 0
30# include <sys/stddef.h>
33# include <click/simclick.h>
35#if !CLICK_PACKET_USE_DPDK && \
36 (CLICK_USERLEVEL || CLICK_NS || CLICK_MINIOS) && \
37 (!HAVE_MULTITHREAD || HAVE___THREAD_STORAGE_CLASS) && \
38 HAVE_ALLOW_CLICK_PACKET_POOL
39# define HAVE_CLICK_PACKET_POOL 1
41#ifndef CLICK_PACKET_DEPRECATED_ENUM
42# define CLICK_PACKET_DEPRECATED_ENUM CLICK_DEPRECATED_ENUM
44#include <click/stack.hh>
56#if HAVE_BATCH && HAVE_CLICK_PACKET_POOL
57#define HAVE_BATCH_RECYCLE 1
77#elif CLICK_PACKET_USE_DPDK || HAVE_DPDK_PACKET_POOL || CLICK_PACKET_INSIDE_DPDK
79#elif HAVE_CLICK_PACKET_POOL
90 uint32_t
length, uint32_t
tailroom,
bool clear =
true) CLICK_WARN_UNUSED_RESULT;
93#if HAVE_DPDK && !CLICK_PACKET_USE_DPDK
95 uint32_t
length, uint32_t
tailroom,
bool clear) CLICK_WARN_UNUSED_RESULT;
99 static Packet *
make(
struct sk_buff *skb) CLICK_WARN_UNUSED_RESULT;
100#elif CLICK_PACKET_USE_DPDK
101 static Packet *
make(
struct rte_mbuf *mb,
bool clear =
true) CLICK_WARN_UNUSED_RESULT;
106 static inline Packet *
make(
struct mbuf *mbuf) CLICK_WARN_UNUSED_RESULT;
109#if CLICK_USERLEVEL || CLICK_MINIOS
110 typedef void (*buffer_destructor_type)(
unsigned char* buf,
size_t sz,
void* argument);
120 buffer_destructor_type buffer_destructor,
121 void* argument = (
void*) 0,
int headroom = 0,
int tailroom = 0,
bool clear =
true) CLICK_WARN_UNUSED_RESULT;
125 static int max_data_pool_size();
126 static void static_cleanup();
132 inline bool shared()
const;
134 Packet *
clone(
bool fast =
false) CLICK_WARN_UNUSED_RESULT;
135 WritablePacket *duplicate(int32_t extra_headroom = 0, int32_t extra_tailroom = 0, const
bool data_only=true) CLICK_WARN_UNUSED_RESULT;
137#ifndef CLICK_NOINDIRECT
138# if CLICK_LINUXMODULE
139 inline void get() {skb_get(skb());};
140# elif CLICK_PACKET_USE_DPDK
141 inline void get() {rte_mbuf_refcnt_update(mb(), 1);};
143 inline void get() {_use_count++;};
147 inline const unsigned char *
data()
const;
148 inline const unsigned char *
end_data()
const;
149 inline uint32_t
length()
const;
152 inline const unsigned char *
buffer()
const;
153 inline const unsigned char *
end_buffer()
const;
157 struct sk_buff *skb() {
return (
struct sk_buff *)
this; }
158 const struct sk_buff *skb()
const {
return (
const struct sk_buff*)
this; }
159#elif CLICK_PACKET_USE_DPDK
160 inline void prefetch_anno() {
161 rte_prefetch0(xanno());
164 struct rte_mbuf *mb() {
165 return reinterpret_cast<struct rte_mbuf *
>(
this);
167 const struct rte_mbuf *mb()
const {
168 return reinterpret_cast<const struct rte_mbuf *
>(
this);
170 void *destructor_argument()
const {
171 click_chatter(
"ILLEGAL CALL TO destructor_argument");
176 void set_buffer_destructor(buffer_destructor_type) {
177 click_chatter(
"ILLEGAL CALL TO set_buffer_destructor");
180 void set_destructor_argument(
void*) {
181 click_chatter(
"ILLEGAL CALL TO set_destructor_argument");
185 struct mbuf *m() {
return _m; }
186 const struct mbuf *m()
const {
return (
const struct mbuf *)_m; }
187 struct mbuf *steal_m();
188 struct mbuf *dup_jumbo_m(
struct mbuf *mbuf);
189#elif CLICK_USERLEVEL || CLICK_MINIOS
190 void set_buffer_destructor(buffer_destructor_type destructor) {
191 _destructor = destructor;
194 buffer_destructor_type buffer_destructor()
const {
198 void* destructor_argument()
const {
199 return _destructor_argument;
202 void reset_buffer() {
203 _head = _data = _tail = _end = 0;
207 void set_destructor_argument(
void* arg) {
208 _destructor_argument = arg;
211 static inline void release_buffer(
unsigned char* head);
212 inline void delete_buffer(
unsigned char* head,
unsigned char* end);
286 void pull(uint32_t len);
344 void take(uint32_t len);
371 Packet *
shift_data(
int offset,
bool free_on_failure =
true) CLICK_WARN_UNUSED_RESULT;
372#if CLICK_USERLEVEL || CLICK_MINIOS
375 inline void change_buffer_length(uint32_t
length);
383 inline const unsigned char *
mac_header()
const;
412 inline const click_ip *
ip_header()
const;
415 inline void set_ip_header(
const click_ip *iph, uint32_t len);
427 inline uint16_t getContentOffset()
const;
428 inline void setContentOffset(uint16_t offset);
429 inline const unsigned char* getPacketContent();
430 inline bool isPacketContentEmpty()
const;
431 inline uint16_t getPacketContentSize()
const;
435# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) && NET_SKBUFF_DATA_USES_OFFSET) || \
436 (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
438 typedef typeof(((
struct sk_buff*)0)->
mac_header) mac_header_type;
439 typedef typeof(((
struct sk_buff*)0)->
network_header) network_header_type;
440 typedef typeof(((
struct sk_buff*)0)->
transport_header) transport_header_type;
448 const Anno *xanno()
const {
return (
const Anno *)skb()->cb; }
449 Anno *xanno() {
return (Anno *)skb()->cb; }
450#elif CLICK_PACKET_USE_DPDK
451 # define ANNO_OFFSET sizeof(struct rte_mbuf)
452 const Anno *xanno()
const {
453 return (
const Anno *) (((
unsigned char*)
this) + ANNO_OFFSET); }
455 return (Anno *) (((
unsigned char*)
this) + ANNO_OFFSET); }
458 CLICK_OPTNONE
const Anno *xanno()
const {
return (
const Anno *) &all_anno()->cb; }
459 CLICK_OPTNONE Anno *xanno() {
return (Anno *) &all_anno()->cb; }
461 inline const Anno *xanno()
const {
return (
const Anno *) &all_anno()->cb; }
462 inline Anno *xanno() {
return (Anno *) &all_anno()->cb; }
510 class SimPacketinfoWrapper {
public:
511 simclick_simpacketinfo _pinfo;
512 SimPacketinfoWrapper() {
520 memset(&_pinfo,-1,
sizeof(_pinfo));
523 simclick_simpacketinfo *get_sim_packetinfo() {
524 return &(_sim_packetinfo._pinfo);
526 void set_sim_packetinfo(simclick_simpacketinfo* pinfo) {
527 _sim_packetinfo._pinfo = *pinfo;
545 inline Packet* find_tail() {
547 while (head != NULL) {
549 if (
next == NULL)
break;
555 inline unsigned int find_count() {
558 while (head != NULL) {
566 dst_ip_anno_offset = 0, dst_ip_anno_size = 4,
567 dst_ip6_anno_offset = 0, dst_ip6_anno_size = 16
583 void *
anno() {
return xanno(); }
586 const void *
anno()
const {
return xanno(); }
589 uint8_t *
anno_u8() {
return &xanno()->u8[0]; }
592 const uint8_t *
anno_u8()
const {
return &xanno()->u8[0]; }
598 const uint32_t *
anno_u32()
const {
return &xanno()->u32[0]; }
604 return xanno()->u8[i];
623#if !HAVE_INDIFFERENT_ALIGNMENT
626 return *
reinterpret_cast<const click_aliasable_uint16_t *
>(xanno()->c + i);
638#if !HAVE_INDIFFERENT_ALIGNMENT
641 *
reinterpret_cast<click_aliasable_uint16_t *
>(xanno()->c + i) = x;
651#if !HAVE_INDIFFERENT_ALIGNMENT
654 return *
reinterpret_cast<const click_aliasable_int16_t *
>(xanno()->c + i);
666#if !HAVE_INDIFFERENT_ALIGNMENT
669 *
reinterpret_cast<click_aliasable_int16_t *
>(xanno()->c + i) = x;
679#if !HAVE_INDIFFERENT_ALIGNMENT
682 return *
reinterpret_cast<const click_aliasable_uint32_t *
>(xanno()->c + i);
694#if !HAVE_INDIFFERENT_ALIGNMENT
697 *
reinterpret_cast<click_aliasable_uint32_t *
>(xanno()->c + i) = x;
706#if !HAVE_INDIFFERENT_ALIGNMENT
709 return *
reinterpret_cast<const click_aliasable_int32_t *
>(xanno()->c + i);
721#if !HAVE_INDIFFERENT_ALIGNMENT
724 *
reinterpret_cast<click_aliasable_int32_t *
>(xanno()->c + i) = x;
735#if !HAVE_INDIFFERENT_ALIGNMENT
736 assert(i % __alignof__(uint64_t) == 0);
738 return *
reinterpret_cast<const click_aliasable_uint64_t *
>(xanno()->c + i);
750#if !HAVE_INDIFFERENT_ALIGNMENT
751 assert(i % __alignof__(uint64_t) == 0);
753 *
reinterpret_cast<click_aliasable_uint64_t *
>(xanno()->c + i) = x;
763 assert(i >= 0 && i <=
anno_size - (
int)
sizeof(
void *));
764#if !HAVE_INDIFFERENT_ALIGNMENT
765 assert(i % __alignof__(
void *) == 0);
767 return *
reinterpret_cast<const click_aliasable_void_pointer_t *
>(xanno()->c + i);
778 assert(i >= 0 && i <=
anno_size - (
int)
sizeof(
void *));
779#if !HAVE_INDIFFERENT_ALIGNMENT
780 assert(i % __alignof__(
void *) == 0);
782 *
reinterpret_cast<click_aliasable_void_pointer_t *
>(xanno()->c + i) =
const_cast<void *
>(x);
785#if !CLICK_PACKET_USE_DPDK && !CLICK_LINUXMODULE && !defined(CLICK_NOINDIRECT)
786 inline Packet* data_packet() {
789 inline void set_data_packet(
Packet* p) {
791 _data_packet->_use_count ++;
794 inline Packet* data_packet() {
801 inline void copy_headers(
const Packet *);
808 addr_anno_offset = 0,
810 user_anno_offset = 16,
812 ADDR_ANNO_SIZE = addr_anno_size,
813 USER_ANNO_SIZE = user_anno_size,
814 USER_ANNO_U16_SIZE = USER_ANNO_SIZE / 2,
815 USER_ANNO_U32_SIZE = USER_ANNO_SIZE / 4,
816 USER_ANNO_U64_SIZE = USER_ANNO_SIZE / 8
817 } CLICK_PACKET_DEPRECATED_ENUM;
818 inline const unsigned char *buffer_data() const CLICK_DEPRECATED;
819 inline
void *addr_anno() CLICK_DEPRECATED;
820 inline const
void *addr_anno() const CLICK_DEPRECATED;
821 inline
void *user_anno() CLICK_DEPRECATED;
822 inline const
void *user_anno() const CLICK_DEPRECATED;
823 inline uint8_t *user_anno_u8() CLICK_DEPRECATED;
824 inline const uint8_t *user_anno_u8() const CLICK_DEPRECATED;
825 inline uint32_t *user_anno_u32() CLICK_DEPRECATED;
826 inline const uint32_t *user_anno_u32() const CLICK_DEPRECATED;
827 inline uint8_t user_anno_u8(
int i) const CLICK_DEPRECATED;
828 inline
void set_user_anno_u8(
int i, uint8_t v) CLICK_DEPRECATED;
829 inline uint16_t user_anno_u16(
int i) const CLICK_DEPRECATED;
830 inline
void set_user_anno_u16(
int i, uint16_t v) CLICK_DEPRECATED;
831 inline uint32_t user_anno_u32(
int i) const CLICK_DEPRECATED;
832 inline
void set_user_anno_u32(
int i, uint32_t v) CLICK_DEPRECATED;
833 inline int32_t user_anno_s32(
int i) const CLICK_DEPRECATED;
834 inline
void set_user_anno_s32(
int i, int32_t v) CLICK_DEPRECATED;
836 inline uint64_t user_anno_u64(
int i)
const CLICK_DEPRECATED;
837 inline void set_user_anno_u64(
int i, uint64_t v) CLICK_DEPRECATED;
839 inline const uint8_t *all_user_anno() const CLICK_DEPRECATED;
840 inline uint8_t *all_user_anno() CLICK_DEPRECATED;
841 inline const uint32_t *all_user_anno_u() const CLICK_DEPRECATED;
842 inline uint32_t *all_user_anno_u() CLICK_DEPRECATED;
843 inline uint8_t user_anno_c(
int) const CLICK_DEPRECATED;
844 inline
void set_user_anno_c(
int, uint8_t) CLICK_DEPRECATED;
845 inline int16_t user_anno_s(
int) const CLICK_DEPRECATED;
846 inline
void set_user_anno_s(
int, int16_t) CLICK_DEPRECATED;
847 inline uint16_t user_anno_us(
int) const CLICK_DEPRECATED;
848 inline
void set_user_anno_us(
int, uint16_t) CLICK_DEPRECATED;
849 inline int32_t user_anno_i(
int) const CLICK_DEPRECATED;
850 inline
void set_user_anno_i(
int, int32_t) CLICK_DEPRECATED;
851 inline uint32_t user_anno_u(
int) const CLICK_DEPRECATED;
852 inline
void set_user_anno_u(
int, uint32_t) CLICK_DEPRECATED;
870#if !CLICK_LINUXMODULE
881#if !CLICK_PACKET_USE_DPDK
893# if CLICK_PACKET_USE_DPDK
894 inline struct AllAnno *all_anno() {
895 return reinterpret_cast<AllAnno *
>(xanno());
897 inline const struct AllAnno *all_anno()
const {
898 return reinterpret_cast<const AllAnno *
>(xanno());
900 static struct rte_mempool **_pktmbuf_pools;
901# elif INLINED_ALLANNO
902 CLICK_OPTNONE
const class Packet* all_anno()
const {
return this;}
903 CLICK_OPTNONE
class Packet* all_anno() {
return this;}
905 CLICK_ALWAYS_INLINE
const struct AllAnno* all_anno()
const {
return &_aa;}
906 CLICK_ALWAYS_INLINE
struct AllAnno* all_anno() {
return &_aa;}
911#if !(CLICK_LINUXMODULE || CLICK_PACKET_USE_DPDK)
914#ifndef CLICK_NOINDIRECT
915# ifndef HAVE_FULLPUSH_NONATOMIC
916 nonatomic_uint32_t _use_count;
924 unsigned char *_head;
925 unsigned char *_data;
926 unsigned char *_tail;
935 SimPacketinfoWrapper _sim_packetinfo;
937# if CLICK_USERLEVEL || CLICK_MINIOS
938 buffer_destructor_type _destructor;
939 void* _destructor_argument;
945 panic(
"Packet constructor");
946#elif CLICK_PACKET_USE_DPDK
947 rte_panic(
"Packet constructor");
954#if !(CLICK_LINUXMODULE || CLICK_PACKET_USE_DPDK)
958 static void assimilate_mbuf(
Packet *p);
959 void assimilate_mbuf();
962 inline void shift_header_annotations(
const unsigned char *old_head, int32_t extra_headroom);
963 WritablePacket *expensive_uniqueify(int32_t extra_headroom, int32_t extra_tailroom,
bool free_on_failure) CLICK_WARN_UNUSED_RESULT;
964 WritablePacket *expensive_push(uint32_t nbytes) CLICK_WARN_UNUSED_RESULT;
965 WritablePacket *expensive_put(uint32_t nbytes) CLICK_WARN_UNUSED_RESULT;
970 friend class DPDKDevice;
975#if HAVE_CLICK_PACKET_POOL
979#if HAVE_VECTOR_PACKET_POOL
982 p(0), pcount(0), pd(0), pdcount(0)
986#if HAVE_VECTOR_PACKET_POOL
995 # if HAVE_MULTITHREAD
996 PacketPool* thread_pool_next;
1001#include <clicknet/tcp.h>
1002#include <clicknet/udp.h>
1006 inline unsigned char *
data()
const;
1007 inline unsigned char *end_data()
const;
1008 inline unsigned char *buffer()
const;
1009 inline unsigned char *end_buffer()
const;
1010 inline unsigned char *mac_header()
const;
1011 inline click_ether *ether_header()
const;
1012 inline unsigned char *network_header()
const;
1013 inline click_ip *ip_header()
const;
1014 inline click_ip6 *ip6_header()
const;
1015 inline unsigned char *transport_header()
const;
1016 inline click_icmp *icmp_header()
const;
1017 inline click_tcp *tcp_header()
const;
1018 inline click_udp *udp_header()
const;
1019 inline unsigned char* getPacketContent();
1021 inline void rewrite_ips(IPPair pair,
bool is_tcp =
true);
1022 inline void rewrite_ips_ports(IPPair pair, uint16_t sport, uint16_t dport,
bool is_tcp =
true);
1023 inline void rewrite_ipport(
IPAddress ip, uint16_t port,
const int shift,
bool is_tcp =
true);
1024 inline void rewrite_ip(
IPAddress ip,
const int shift,
bool is_tcp =
true);
1025 inline void rewrite_seq(tcp_seq_t seq,
const int shift);
1027#if !CLICK_LINUXMODULE
1028# if HAVE_DPDK && !CLICK_PACKET_USE_DPDK
1029 inline void set_mbuf(rte_mbuf* mbuf, uint32_t
length);
1031 inline void init_buffer(
unsigned char *
data, uint32_t
buffer_length, uint32_t data_length);
1032 inline void set_buffer(
unsigned char *buffer, uint32_t
buffer_length);
1033 inline void set_data(
unsigned char *
data);
1034 inline void set_data_length(uint32_t
length);
1037# if HAVE_CLICK_PACKET_POOL
1038 static PacketPool& get_local_packet_pool();
1039 static void initialize_local_packet_pool();
1044 static void pool_consumed_data_burst(uint16_t n,
WritablePacket* tail);
1046#if !CLICK_LINUXMODULE
1047 inline void init_buffer(
unsigned char *
data, uint32_t
length) {
1051 inline void init_buffer(
unsigned char *
data) {
1057 if (!
next())
return NULL;
1066 if (!
prev())
return NULL;
1074 #if !CLICK_LINUXMODULE || CLICK_PACKET_USE_DPDK
1075 inline void initialize(
bool clear);
1076 inline void initialize_data();
1081 inline unsigned char *buffer_data()
const CLICK_DEPRECATED;
1088#if HAVE_CLICK_PACKET_POOL
1092 uint32_t
tailroom,
bool clear =
true);
1094 static void check_data_pool_size(PacketPool &packet_pool,
unsigned n);
1095 static void check_packet_pool_size(PacketPool &packet_pool,
unsigned n);
1105 friend class NetmapDevice;
1106 friend class FromDPDKDevice;
1125#if CLICK_LINUXMODULE || INLINED_ALLANNO
1126 memset(xanno(), 0,
sizeof(Anno));
1139#elif CLICK_PACKET_USE_DPDK
1140 memset(all_anno(), 0, all ?
sizeof(AllAnno) :
sizeof(Anno));
1143 memset(&_aa, 0, all ?
sizeof(AllAnno) :
sizeof(Anno));
1158 *xanno() = *p->xanno();
1165#if !CLICK_LINUXMODULE
1167WritablePacket::initialize(
bool clear)
1169#if CLICK_PACKET_USE_DPDK
1170 click_chatter(
"UNIMPLEMENTED");
1173#if !CLICK_NOINDIRECT
1177# if CLICK_USERLEVEL || CLICK_MINIOS
1179# elif CLICK_BSDMODULE
1187WritablePacket::initialize_data()
1189#if CLICK_PACKET_USE_DPDK
1191 click_chatter(
"UNIMPLEMENTED");
1194# if !CLICK_NOINDIRECT
1206inline const unsigned char *
1209#if CLICK_LINUXMODULE
1211#elif CLICK_PACKET_USE_DPDK
1212 return rte_pktmbuf_mtod(mb(),
const unsigned char *);
1222inline const unsigned char *
1225#if CLICK_LINUXMODULE
1226# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
1227 return skb_tail_pointer(skb());
1231#elif CLICK_PACKET_USE_DPDK
1242inline const unsigned char *
1245#if CLICK_LINUXMODULE
1247#elif CLICK_PACKET_USE_DPDK
1248 return (
const unsigned char*)mb()->buf_addr;
1258inline const unsigned char *
1261#if CLICK_LINUXMODULE
1262# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
1263 return skb_end_pointer(skb());
1267#elif CLICK_PACKET_USE_DPDK
1268 return end_data() + rte_pktmbuf_tailroom(mb());
1278#if CLICK_LINUXMODULE
1280#elif CLICK_PACKET_USE_DPDK
1281 return rte_pktmbuf_data_len(mb());
1283 return _tail - _data;
1295#if CLICK_PACKET_USE_DPDK
1296 return rte_pktmbuf_headroom(mb());
1310#if CLICK_PACKET_USE_DPDK
1311 return rte_pktmbuf_tailroom(mb());
1329#if CLICK_LINUXMODULE
1330 return (
Packet *)(skb()->next);
1331#elif INLINED_ALLANNO
1332 return all_anno()->nextp;
1334 return all_anno()->
next;
1341#if CLICK_LINUXMODULE
1342 return (
Packet *&)(skb()->next);
1343#elif INLINED_ALLANNO
1344 return all_anno()->nextp;
1346 return all_anno()->
next;
1353#if CLICK_LINUXMODULE
1354 skb()->next = p->skb();
1355#elif INLINED_ALLANNO
1356 all_anno()->nextp = p;
1358 all_anno()->
next = p;
1365#if CLICK_LINUXMODULE
1366 return (
Packet *)(skb()->prev);
1367#elif INLINED_ALLANNO
1368 return all_anno()->prevp;
1370 return all_anno()->
prev;
1377#if CLICK_LINUXMODULE
1378 return (
Packet *&)(skb()->prev);
1379#elif INLINED_ALLANNO
1380 return all_anno()->prevp;
1382 return all_anno()->
prev;
1389#if CLICK_LINUXMODULE
1390 skb()->prev = p->skb();
1391#elif INLINED_ALLANNO
1392 all_anno()->prevp = p;
1394 all_anno()->
prev = p;
1403#if CLICK_LINUXMODULE
1404# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
1405 return skb_mac_header_was_set(skb());
1407 return skb()->mac.raw != 0;
1410 return all_anno()->mac != 0;
1418inline const unsigned char *
1421#if CLICK_LINUXMODULE
1422# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
1423 return skb_mac_header(skb());
1425 return skb()->mac.raw;
1428 return all_anno()->mac;
1437#if CLICK_LINUXMODULE
1438# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
1439# if NET_SKBUFF_DATA_USES_OFFSET
1440 return skb()->network_header != (network_header_type) ~0U;
1442 return skb()->network_header != 0;
1445 return skb()->nh.raw != 0;
1448 return all_anno()->nh != 0;
1456inline const unsigned char *
1459#if CLICK_LINUXMODULE
1460# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
1461 return skb_network_header(skb());
1463 return skb()->nh.raw;
1466 return all_anno()->nh;
1475#if CLICK_LINUXMODULE
1476# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
1477# if NET_SKBUFF_DATA_USES_OFFSET
1478 return skb()->transport_header != (transport_header_type) ~0U;
1480 return skb()->transport_header != 0;
1483 return skb()->h.raw != 0;
1486 return all_anno()->h != 0;
1494inline const unsigned char *
1497#if CLICK_LINUXMODULE
1498# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
1499 return skb_transport_header(skb());
1501 return skb()->h.raw;
1504 return all_anno()->h;
1512inline const click_ether *
1515 return reinterpret_cast<const click_ether *
>(
mac_header());
1522inline const click_ip *
1532inline const click_ip6 *
1542inline const click_icmp *
1552inline const click_tcp *
1562inline const click_udp *
1598#if CLICK_LINUXMODULE
1599# if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 13)
1600 return *
reinterpret_cast<const Timestamp*
>(&skb()->stamp);
1602 return *
reinterpret_cast<const Timestamp*
>(&skb()->tstamp);
1604#elif CLICK_PACKET_USE_DPDK
1605 return *(
Timestamp*)&(TIMESTAMP_FIELD(mb()));
1607 return *
reinterpret_cast<const Timestamp*
>(&all_anno()->timestamp);
1614#if CLICK_LINUXMODULE
1615# if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 13)
1616 return *
reinterpret_cast<Timestamp*
>(&skb()->stamp);
1618 return *
reinterpret_cast<Timestamp*
>(&skb()->tstamp);
1620#elif CLICK_PACKET_USE_DPDK
1621 return *(
Timestamp*)&(TIMESTAMP_FIELD(mb()));
1623 return *
reinterpret_cast<Timestamp*
>(&all_anno()->timestamp);
1636#if CLICK_LINUXMODULE
1638#elif CLICK_BSDMODULE
1640 return m()->m_pkthdr.rcvif;
1651#if CLICK_LINUXMODULE
1653#elif CLICK_BSDMODULE
1655 m()->m_pkthdr.rcvif = dev;
1664#if CLICK_LINUXMODULE && PACKET_TYPE_MASK
1665 return (
PacketType)(skb()->pkt_type & PACKET_TYPE_MASK);
1666#elif CLICK_LINUXMODULE
1669 return all_anno()->pkt_type;
1676#if CLICK_LINUXMODULE && PACKET_TYPE_MASK
1677 skb()->pkt_type = (skb()->pkt_type & PACKET_CLEAN) | p;
1678#elif CLICK_LINUXMODULE
1679 skb()->pkt_type = p;
1681 all_anno()->pkt_type = p;
1717#if CLICK_LINUXMODULE
1739 struct sk_buff *nskb;
1740 if (atomic_read(&skb->users) == 1) {
1744 nskb = skb_clone(skb, GFP_ATOMIC);
1745 atomic_dec(&skb->users);
1747# if HAVE_SKB_LINEARIZE
1748# if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 17)
1749 if (nskb && skb_linearize(nskb, GFP_ATOMIC) != 0)
1751 if (nskb && skb_linearize(nskb) != 0)
1758 return reinterpret_cast<Packet *
>(nskb);
1762#if CLICK_PACKET_USE_DPDK
1806#if CLICK_LINUXMODULE
1807 struct sk_buff *b = skb();
1808 b->next = b->prev = 0;
1809 # if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 15)
1812 skbmgr_recycle_skbs(b);
1813#elif CLICK_PACKET_USE_DPDK
1814 # if HAVE_FLOW_DYNAMIC
1816 fcb_stack->release(1);
1820 rte_pktmbuf_free(mb());
1821#elif HAVE_CLICK_PACKET_POOL && !defined(CLICK_FORCE_EXPENSIVE)
1822 # ifndef CLICK_NOINDIRECT
1823 if (_use_count.dec_and_test())
1829 # if HAVE_FLOW_DYNAMIC
1831 fcb_stack->release(1);
1835# ifndef CLICK_NOINDIRECT
1836 if (_use_count.dec_and_test())
1855#if CLICK_LINUXMODULE
1856 struct sk_buff *b = skb();
1857 b->next = b->prev = 0;
1858 # if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 15)
1861 skbmgr_recycle_skbs(b);
1862#elif CLICK_PACKET_USE_DPDK
1863# if HAVE_FLOW_DYNAMIC
1865 fcb_stack->release(1);
1868 rte_pktmbuf_free(mb());
1869#elif HAVE_CLICK_PACKET_POOL
1871# ifndef CLICK_NOINDIRECT
1872 if (_use_count.nonatomic_dec_and_test())
1879# if HAVE_FLOW_DYNAMIC
1882 click_chatter(
"Release ksn");
1883 fcb_stack->release(1);
1887#ifndef CLICK_NOINDIRECT
1888 if (_use_count.nonatomic_dec_and_test())
1900Packet::assimilate_mbuf(
Packet *p)
1902 struct mbuf *m = p->m();
1906 p->_head = (
unsigned char *)
1907 (m->m_flags & M_EXT ? m->m_ext.ext_buf :
1908 m->m_flags & M_PKTHDR ? m->m_pktdat :
1910 p->_data = (
unsigned char *)m->m_data;
1911 p->_tail = (
unsigned char *)(m->m_data + m->m_len);
1912 p->_end = p->_head +
1913 (m->m_flags & M_EXT ? min(m->m_pkthdr.len, m->m_ext.ext_size) :
1914 m->m_flags & M_PKTHDR ? MHLEN :
1919Packet::assimilate_mbuf()
1921 assimilate_mbuf(
this);
1927 if (!(m->m_flags & M_PKTHDR))
1928 panic(
"trying to construct Packet from a non-packet mbuf");
1935#ifndef CLICK_NOINDIRECT
1937 p->_data_packet = NULL;
1939 if (m->m_pkthdr.len != m->m_len) {
1943 if (m->m_pkthdr.len <= MCLBYTES) {
1945 m2 = m_pulldown(m, 0, m->m_pkthdr.len, NULL);
1947 panic(
"m_pulldown failed");
1955 m2 = m_defrag(m, M_DONTWAIT);
1964 m2 = p->dup_jumbo_m(m);
1987#ifdef CLICK_NOINDIRECT
1990# if CLICK_LINUXMODULE
1991 return skb_cloned(
const_cast<struct sk_buff *
>(skb()));
1992# elif CLICK_PACKET_USE_DPDK
1993 return rte_mbuf_refcnt_read(mb()) > 1 || RTE_MBUF_INDIRECT(mb());
1995 return (_data_packet || _use_count > 1);
2007#ifdef CLICK_NOINDIRECT
2010# if CLICK_LINUXMODULE
2011 return skb_cloned(
const_cast<struct sk_buff *
>(skb()));
2012# elif CLICK_PACKET_USE_DPDK
2013 return rte_mbuf_refcnt_read(mb()) > 1 || RTE_MBUF_INDIRECT(mb());
2015 return (_data_packet || _use_count.nonatomic_value() > 1);
2023 PacketRef(
Packet* p) : _p(p->clone()) { }
2024 ~PacketRef() {
if (_p) _p->kill(); }
2060#ifdef CLICK_NOINDIRECT
2063# ifdef CLICK_FORCE_EXPENSIVE
2069 return expensive_uniqueify(0, 0,
true);
2076#ifdef CLICK_FORCE_EXPENSIVE
2081#if CLICK_LINUXMODULE
2082 __skb_push(q->skb(), len);
2083#elif CLICK_PACKET_USE_DPDK
2084 rte_pktmbuf_prepend(q->mb(), len);
2088 q->m()->m_data -= len;
2089 q->m()->m_len += len;
2090 q->m()->m_pkthdr.len += len;
2095 return expensive_push(len);
2103#if CLICK_LINUXMODULE
2104 __skb_push(skb(), len);
2105#elif CLICK_PACKET_USE_DPDK
2106 rte_pktmbuf_prepend(mb(), len);
2112 m()->m_pkthdr.len += len;
2117 return expensive_push(len);
2125 click_chatter(
"Packet::pull %d > length %d\n", len,
length());
2128#if CLICK_LINUXMODULE
2129 __skb_pull(skb(), len);
2130#elif CLICK_PACKET_USE_DPDK
2131 mb()->data_off += len;
2132 mb()->data_len -= len;
2133 mb()->pkt_len -= len;
2139 m()->m_pkthdr.len -= len;
2147#ifdef CLICK_FORCE_EXPENSIVE
2152#if CLICK_LINUXMODULE
2153 __skb_put(q->skb(), len);
2154#elif CLICK_PACKET_USE_DPDK
2155 rte_pktmbuf_append(q->mb(), len);
2159 q->m()->m_len += len;
2160 q->m()->m_pkthdr.len += len;
2165 return expensive_put(len);
2172#if CLICK_LINUXMODULE
2173 __skb_put(skb(), len);
2174#elif CLICK_PACKET_USE_DPDK
2175 rte_pktmbuf_append(mb(), len);
2180 m()->m_pkthdr.len += len;
2185 return expensive_put(len);
2192 click_chatter(
"Packet::take %d > length %d\n", len,
length());
2195#if CLICK_LINUXMODULE
2198#elif CLICK_PACKET_USE_DPDK
2199 rte_pktmbuf_trim(mb(), len);
2204 m()->m_pkthdr.len -= len;
2209#if CLICK_USERLEVEL || CLICK_MINIOS
2238# if CLICK_PACKET_USE_DPDK
2245#ifndef CLICK_NOINDIRECT
2246 assert(_data_packet);
2249 _head = _data =
const_cast<unsigned char *
>(
data);
2250 _tail = _end =
const_cast<unsigned char *
>(
data +
length);
2276# if CLICK_PACKET_USE_DPDK
2277 rte_pktmbuf_prepend(mb(), this->
headroom());
2279 rte_pktmbuf_data_len(mb()) =
length;
2289Packet::change_buffer_length(uint32_t length)
2291# if CLICK_PACKET_USE_DPDK
2292 rte_panic(
"Not allowed with DPDK");
2302 return IPAddress(xanno()->u32[dst_ip_anno_offset / 4]);
2308 xanno()->u32[dst_ip_anno_offset / 4] = a.
addr();
2317#if CLICK_LINUXMODULE
2318# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
2319 skb_set_mac_header(skb(), p -
data());
2321 skb()->mac.raw =
const_cast<unsigned char *
>(p);
2324 all_anno()->mac =
const_cast<unsigned char *
>(p);
2336#if CLICK_LINUXMODULE
2337# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
2338 skb_set_mac_header(skb(), p -
data());
2339 skb_set_network_header(skb(), (p + len) -
data());
2341 skb()->mac.raw =
const_cast<unsigned char *
>(p);
2342 skb()->nh.raw =
const_cast<unsigned char *
>(p) + len;
2345 all_anno()->mac =
const_cast<unsigned char *
>(p);
2346 all_anno()->nh =
const_cast<unsigned char *
>(p) + len;
2358 set_mac_header(
reinterpret_cast<const unsigned char *
>(ethh), 14);
2367#if CLICK_LINUXMODULE
2368# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) && NET_SKBUFF_DATA_USES_OFFSET
2369 skb()->mac_header = (mac_header_type) ~0U;
2370# elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
2371 skb()->mac_header = 0;
2376 all_anno()->mac = 0;
2383#ifdef CLICK_FORCE_EXPENSIVE
2389#if CLICK_LINUXMODULE
2390 __skb_push(q->skb(), len);
2391#elif CLICK_PACKET_USE_DPDK
2392 rte_pktmbuf_prepend(q->mb(), len);
2396 q->m()->m_data -= len;
2397 q->m()->m_len += len;
2398 q->m()->m_pkthdr.len += len;
2401 }
else if ((q = expensive_push(len)))
2415#if CLICK_LINUXMODULE
2416# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
2417 skb_set_network_header(skb(), p -
data());
2419 skb()->nh.raw =
const_cast<unsigned char *
>(p);
2422 all_anno()->nh =
const_cast<unsigned char *
>(p);
2432#if CLICK_LINUXMODULE
2433# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
2434 skb_set_transport_header(skb(), p -
data());
2436 skb()->h.raw =
const_cast<unsigned char *
>(p);
2439 all_anno()->h =
const_cast<unsigned char *
>(p);
2451#if CLICK_LINUXMODULE
2452# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
2453 skb_set_network_header(skb(), p -
data());
2454 skb_set_transport_header(skb(), (p + len) -
data());
2456 skb()->nh.raw =
const_cast<unsigned char *
>(p);
2457 skb()->h.raw =
const_cast<unsigned char *
>(p) + len;
2460 all_anno()->nh =
const_cast<unsigned char *
>(p);
2461 all_anno()->h =
const_cast<unsigned char *
>(p) + len;
2475#if CLICK_LINUXMODULE
2476# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
2479 skb()->h.raw = skb()->nh.raw + len;
2482 all_anno()->h = all_anno()->nh + len;
2527#if CLICK_LINUXMODULE
2528# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) && NET_SKBUFF_DATA_USES_OFFSET
2529 skb()->network_header = (network_header_type) ~0U;
2530# elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
2531 skb()->network_header = 0;
2643#if CLICK_LINUXMODULE
2644# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) && NET_SKBUFF_DATA_USES_OFFSET
2645 skb()->transport_header = (transport_header_type) ~0U;
2646# elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
2647 skb()->transport_header = 0;
2657Packet::shift_header_annotations(
const unsigned char *old_head,
2658 int32_t extra_headroom)
2660#if CLICK_LINUXMODULE
2661 struct sk_buff *mskb = skb();
2665# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) && NET_SKBUFF_DATA_USES_OFFSET) || \
2666 (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
2668 mskb->mac_header += (mskb->mac_header == (mac_header_type) ~0U ? 0 : extra_headroom);
2669 mskb->network_header += (mskb->network_header == (network_header_type) ~0U ? 0 : extra_headroom);
2670 mskb->transport_header += (mskb->transport_header == (transport_header_type) ~0U ? 0 : extra_headroom);
2671# elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
2672 ptrdiff_t shift = (mskb->head - old_head) + extra_headroom;
2673 mskb->mac_header += (mskb->mac_header ? shift : 0);
2674 mskb->network_header += (mskb->network_header ? shift : 0);
2675 mskb->transport_header += (mskb->transport_header ? shift : 0);
2677 ptrdiff_t shift = (mskb->head - old_head) + extra_headroom;
2678 mskb->mac.raw += (mskb->mac.raw ? shift : 0);
2679 mskb->nh.raw += (mskb->nh.raw ? shift : 0);
2680 mskb->h.raw += (mskb->h.raw ? shift : 0);
2682#elif CLICK_PACKET_USE_DPDK
2683 ptrdiff_t shift = (
buffer() - old_head) + extra_headroom;
2684 all_anno()->mac += (all_anno()->mac ? shift : 0);
2685 all_anno()->nh += (all_anno()->nh ? shift : 0);
2686 all_anno()->h += (all_anno()->h ? shift : 0);
2688 ptrdiff_t shift = (_head - old_head) + extra_headroom;
2689 all_anno()->mac += (all_anno()->mac ? shift : 0);
2690 all_anno()->nh += (all_anno()->nh ? shift : 0);
2691 all_anno()->h += (all_anno()->h ? shift : 0);
2698inline const unsigned char *
2699Packet::buffer_data()
const
2708inline void *Packet::addr_anno() {
2709 return anno_u8() + addr_anno_offset;
2713inline const void *Packet::addr_anno()
const {
2714 return anno_u8() + addr_anno_offset;
2721inline void *Packet::user_anno() {
2722 return anno_u8() + user_anno_offset;
2726inline const void *Packet::user_anno()
const {
2727 return anno_u8() + user_anno_offset;
2732inline uint8_t *Packet::user_anno_u8() {
2733 return anno_u8() + user_anno_offset;
2737inline const uint8_t *Packet::user_anno_u8()
const {
2738 return anno_u8() + user_anno_offset;
2743inline uint32_t *Packet::user_anno_u32() {
2744 return anno_u32() + user_anno_offset / 4;
2748inline const uint32_t *Packet::user_anno_u32()
const {
2749 return anno_u32() + user_anno_offset / 4;
2756inline uint8_t Packet::user_anno_u8(
int i)
const {
2757 return anno_u8(user_anno_offset + i);
2765inline void Packet::set_user_anno_u8(
int i, uint8_t v) {
2775inline uint16_t Packet::user_anno_u16(
int i)
const {
2776 return anno_u16(user_anno_offset + i * 2);
2786inline void Packet::set_user_anno_u16(
int i, uint16_t v) {
2796inline uint32_t Packet::user_anno_u32(
int i)
const {
2797 return anno_u32(user_anno_offset + i * 4);
2807inline void Packet::set_user_anno_u32(
int i, uint32_t v) {
2817inline int32_t Packet::user_anno_s32(
int i)
const {
2818 return anno_s32(user_anno_offset + i * 4);
2828inline void Packet::set_user_anno_s32(
int i, int32_t v) {
2839inline uint64_t Packet::user_anno_u64(
int i)
const {
2840 return anno_u64(user_anno_offset + i * 8);
2850inline void Packet::set_user_anno_u64(
int i, uint64_t v) {
2857inline const uint8_t *Packet::all_user_anno()
const {
2858 return anno_u8() + user_anno_offset;
2863inline uint8_t *Packet::all_user_anno() {
2864 return anno_u8() + user_anno_offset;
2869inline const uint32_t *Packet::all_user_anno_u()
const {
2870 return anno_u32() + user_anno_offset / 4;
2875inline uint32_t *Packet::all_user_anno_u() {
2876 return anno_u32() + user_anno_offset / 4;
2881inline uint8_t Packet::user_anno_c(
int i)
const {
2882 return anno_u8(user_anno_offset + i);
2887inline void Packet::set_user_anno_c(
int i, uint8_t v) {
2893inline uint16_t Packet::user_anno_us(
int i)
const {
2894 return anno_u16(user_anno_offset + i * 2);
2899inline void Packet::set_user_anno_us(
int i, uint16_t v) {
2905inline int16_t Packet::user_anno_s(
int i)
const {
2906 return (int16_t)
anno_u16(user_anno_offset + i * 2);
2911inline void Packet::set_user_anno_s(
int i, int16_t v) {
2917inline uint32_t Packet::user_anno_u(
int i)
const {
2918 return anno_u32(user_anno_offset + i * 4);
2923inline void Packet::set_user_anno_u(
int i, uint32_t v) {
2929inline int32_t Packet::user_anno_i(
int i)
const {
2930 return anno_s32(user_anno_offset + i * 4);
2935inline void Packet::set_user_anno_i(
int i, int32_t v) {
2940inline unsigned char *
2946inline unsigned char *
2947WritablePacket::end_data()
const
2952inline unsigned char *
2953WritablePacket::buffer()
const
2958inline unsigned char *
2959WritablePacket::end_buffer()
const
2964inline unsigned char *
2965WritablePacket::mac_header()
const
2970inline unsigned char *
2971WritablePacket::network_header()
const
2976inline unsigned char *
2977WritablePacket::transport_header()
const
2983WritablePacket::ether_header()
const
2989WritablePacket::ip_header()
const
2995WritablePacket::ip6_header()
const
3001WritablePacket::icmp_header()
const
3007WritablePacket::tcp_header()
const
3013WritablePacket::udp_header()
const
3019inline unsigned char *
3020WritablePacket::buffer_data()
const
3026#if !CLICK_LINUXMODULE
3028WritablePacket::init_buffer(
unsigned char *data, uint32_t buffer_length, uint32_t data_length) {
3029# if CLICK_PACKET_USE_DPDK
3030 rte_panic(
"Not allowed with DPDK");
3032 _head = _data =
data;
3033 _tail =
data + data_length;
3038WritablePacket::set_buffer(
unsigned char* buffer, uint32_t buffer_length) {
3039# if CLICK_PACKET_USE_DPDK
3040 rte_panic(
"Not allowed with DPDK");
3047WritablePacket::set_data(
unsigned char* data) {
3048# if CLICK_PACKET_USE_DPDK
3049 rte_panic(
"Not allowed with DPDK");
3055WritablePacket::set_data_length(uint32_t data_length) {
3056# if CLICK_PACKET_USE_DPDK
3057 rte_panic(
"Not allowed with DPDK");
3059 _tail = _data + data_length;
3066 assert(this->network_header());
3067 uint16_t *x =
reinterpret_cast<uint16_t *
>(&this->ip_header()->ip_src);
3068 uint32_t old_hw = (uint32_t) x[0] + x[1] + x[2] + x[3];
3069 old_hw += (old_hw >> 16);
3071 memcpy(x, &pair, 8);
3073 uint32_t new_hw = (uint32_t) x[0] + x[1] + x[2] + x[3];
3074 new_hw += (new_hw >> 16);
3075 click_ip *iph = this->ip_header();
3076 click_update_in_cksum(&iph->ip_sum, old_hw, new_hw);
3078 click_update_in_cksum(&this->tcp_header()->th_sum, old_hw, new_hw);
3080 click_update_in_cksum(&this->udp_header()->uh_sum, old_hw, new_hw);
3084WritablePacket::rewrite_ips_ports(IPPair pair, uint16_t sport, uint16_t dport,
bool is_tcp) {
3085 assert(this->network_header());
3086 assert(this->transport_header());
3087 uint32_t old_hw, t_old_hw;
3088 uint32_t new_hw, t_new_hw;
3090 uint16_t *xip =
reinterpret_cast<uint16_t *
>(&this->ip_header()->ip_src);
3091 old_hw = (uint32_t) xip[0] + xip[1] + xip[2] + xip[3];
3093 old_hw += (old_hw >> 16);
3095 memcpy(xip, &pair, 8);
3097 new_hw = (uint32_t) xip[0] + xip[1] + xip[2] + xip[3];
3099 new_hw += (new_hw >> 16);
3100 click_ip *iph = this->ip_header();
3101 click_update_in_cksum(&iph->ip_sum, old_hw, new_hw);
3103 uint16_t *xport =
reinterpret_cast<uint16_t *
>(&this->tcp_header()->th_sport);
3104 t_old_hw += (uint32_t) xport[0] + xport[1];
3105 t_old_hw += (t_old_hw >> 16);
3110 t_new_hw += (uint32_t) xport[0] + xport[1];
3111 t_new_hw += (t_new_hw >> 16);
3114 click_update_in_cksum(&this->tcp_header()->th_sum, t_old_hw, t_new_hw);
3116 click_update_in_cksum(&this->udp_header()->uh_sum, t_old_hw, t_new_hw);
3121WritablePacket::rewrite_ipport(
IPAddress ip, uint16_t port,
const int shift,
bool is_tcp) {
3122 assert(this->network_header());
3123 assert(this->transport_header());
3124 uint32_t old_hw, t_old_hw;
3125 uint32_t new_hw, t_new_hw;
3127 uint16_t *xip =
reinterpret_cast<uint16_t *
>(&this->ip_header()->ip_src);
3128 old_hw = (uint32_t) xip[(shift * 2) + 0] + xip[(shift*2) + 1];
3130 old_hw += (old_hw >> 16);
3132 memcpy(&xip[shift*2], &ip, 4);
3134 new_hw = (uint32_t) xip[(shift*2) + 0] + xip[(shift*2) + 1];
3136 new_hw += (new_hw >> 16);
3137 click_ip *iph = this->ip_header();
3138 click_update_in_cksum(&iph->ip_sum, old_hw, new_hw);
3140 uint16_t *xport =
reinterpret_cast<uint16_t *
>(&this->tcp_header()->th_sport);
3141 t_old_hw += (uint32_t) xport[shift + 0];
3142 t_old_hw += (t_old_hw >> 16);
3143 xport[shift + 0] = port;
3144 t_new_hw += (uint32_t) xport[shift + 0];
3145 t_new_hw += (t_new_hw >> 16);
3148 click_update_in_cksum(&this->tcp_header()->th_sum, t_old_hw, t_new_hw);
3150 click_update_in_cksum(&this->udp_header()->uh_sum, t_old_hw, t_new_hw);
3155WritablePacket::rewrite_ip(
IPAddress ip,
const int shift,
bool is_tcp) {
3156 assert(this->network_header());
3157 assert(this->transport_header());
3158 uint32_t old_hw, t_old_hw;
3159 uint32_t new_hw, t_new_hw;
3161 uint16_t *xip =
reinterpret_cast<uint16_t *
>(&this->ip_header()->ip_src);
3162 old_hw = (uint32_t) xip[(shift * 2) + 0] + xip[(shift*2) + 1];
3164 old_hw += (old_hw >> 16);
3166 memcpy(&xip[shift*2], &ip, 4);
3168 new_hw = (uint32_t) xip[(shift*2) + 0] + xip[(shift*2) + 1];
3170 new_hw += (new_hw >> 16);
3171 click_ip *iph = this->ip_header();
3172 click_update_in_cksum(&iph->ip_sum, old_hw, new_hw);
3175 click_update_in_cksum(&this->tcp_header()->th_sum, t_old_hw, t_new_hw);
3177 click_update_in_cksum(&this->udp_header()->uh_sum, t_old_hw, t_new_hw);
3182WritablePacket::rewrite_seq(tcp_seq_t seq,
const int shift) {
3183 assert(this->network_header());
3184 assert(this->transport_header());
3185 uint32_t t_old_hw = 0;
3186 uint32_t t_new_hw = 0;
3188 uint16_t *xseq =
reinterpret_cast<uint16_t *
>(&this->tcp_header()->th_seq);
3189 t_old_hw = (uint32_t) xseq[shift * 2];
3190 t_old_hw += (t_old_hw >> 16);
3191 memcpy(&xseq[shift*2], &seq, 4);
3192 t_new_hw = (uint32_t) xseq[shift * 2];
3193 t_new_hw += (t_new_hw >> 16);
3195 click_update_in_cksum(&this->tcp_header()->th_sum, t_old_hw, t_new_hw);
3200inline unsigned char* WritablePacket::getPacketContent()
3202 uint16_t offset = getContentOffset();
3204 return (
data() + offset);
3208inline const unsigned char* Packet::getPacketContent()
3210 uint16_t offset = getContentOffset();
3212 return (
data() + offset);
3215inline bool Packet::isPacketContentEmpty()
const
3217 uint16_t offset = getContentOffset();
3225inline uint16_t Packet::getPacketContentSize()
const
3227 uint16_t offset = getContentOffset();
3229 return length() - offset;
3232inline void Packet::setContentOffset(uint16_t offset)
3237inline uint16_t Packet::getContentOffset()
const
3239 return anno_u16(MIDDLEBOX_CONTENTOFFSET_OFFSET);
An atomic 32-bit integer.
An IPv4 address.
Definition ipaddress.hh:16
uint32_t addr() const
Return the address as a uint32_t in network byte order.
Definition ipaddress.hh:97
Definition packetbatch.hh:415
A network packet.
Definition packet.hh:68
int ip6_header_offset() const
Return the offset from the packet data to the IPv6 header.
Definition packet.hh:2610
const unsigned char * end_buffer() const
Return the packet's end data buffer pointer.
Definition packet.hh:1259
void shrink_data(const unsigned char *data, uint32_t length)
Shrink the packet's data.
Definition packet.hh:2236
void set_ip6_header(const click_ip6 *ip6h)
Set the network header pointer to an IPv6 header.
Definition packet.hh:2516
uint32_t mac_header_length() const
Return the MAC header length.
Definition packet.hh:2556
void clear_transport_header()
Unset the transport header pointer.
Definition packet.hh:2641
void set_anno_u16(int i, uint16_t x)
Set 16-bit annotation at offset i.
Definition packet.hh:636
uint8_t anno_u8(int i) const
Return annotation byte at offset i.
Definition packet.hh:602
static WritablePacket * make(uint32_t headroom, const void *data, uint32_t length, uint32_t tailroom, bool clear=true)
Create and return a new packet.
Definition packet.cc:911
const unsigned char * mac_header() const
Return the packet's MAC header pointer.
Definition packet.hh:1419
void set_anno_u64(int i, uint64_t x)
Set 64-bit annotation at offset i.
Definition packet.hh:748
void set_anno_u32(int i, uint32_t x)
Set 32-bit annotation at offset i.
Definition packet.hh:692
void set_mac_header(const unsigned char *p)
Set the MAC header pointer.
Definition packet.hh:2314
uint32_t anno_u32(int i) const
Return 32-bit annotation at offset i.
Definition packet.hh:677
const click_icmp * icmp_header() const
Return the packet's transport header pointer as ICMP.
Definition packet.hh:1543
WritablePacket * put(uint32_t len)
Add space for data after the packet.
Definition packet.hh:2145
uint32_t * anno_u32()
Return a pointer to the annotation area as uint32_ts.
Definition packet.hh:595
uint16_t anno_u16(int i) const
Return 16-bit annotation at offset i.
Definition packet.hh:621
net_device * device_anno() const
Return the device annotation.
Definition packet.hh:1634
const void * anno() const
Definition packet.hh:586
void * anno_ptr(int i) const
Return void * sized annotation at offset i.
Definition packet.hh:762
bool shared_nonatomic() const
Test whether this packet's data is shared.
Definition packet.hh:2005
void set_dst_ip_anno(IPAddress addr)
Set the destination IPv4 address annotation.
Definition packet.hh:2306
int32_t anno_s32(int i) const
Return 32-bit annotation at offset i.
Definition packet.hh:704
const click_tcp * tcp_header() const
Return the packet's transport header pointer as TCP.
Definition packet.hh:1553
WritablePacket * push_mac_header(uint32_t len)
Add space for a MAC header before the packet.
Definition packet.hh:2381
uint32_t tailroom() const
Return the packet's tailroom.
Definition packet.hh:1308
int16_t anno_s16(int i) const
Return 16-bit annotation at offset i.
Definition packet.hh:649
void kill()
Delete this packet.
Definition packet.hh:1804
void set_next(Packet *p)
Set the next packet annotation.
Definition packet.hh:1351
void pull(uint32_t len)
Remove a header from the front of the packet.
Definition packet.hh:2122
uint64_t anno_u64(int i) const
Return 64-bit annotation at offset i.
Definition packet.hh:733
void set_anno_s32(int i, int32_t x)
Set 32-bit annotation at offset i.
Definition packet.hh:719
uint8_t * anno_u8()
Return a pointer to the annotation area as uint8_ts.
Definition packet.hh:589
Packet * nonunique_push(uint32_t len)
Add space for a header before the packet.
Definition packet.hh:2100
const click_ip6 * ip6_header() const
Return the packet's network header pointer as IPv6.
Definition packet.hh:1533
const click_ip * ip_header() const
Return the packet's network header pointer as IPv4.
Definition packet.hh:1523
Packet * prev() const
Return the previous packet annotation.
Definition packet.hh:1363
const unsigned char * network_header() const
Return the packet's network header pointer.
Definition packet.hh:1457
void set_anno_s16(int i, int16_t x)
Set 16-bit annotation at offset i.
Definition packet.hh:664
void copy_annotations(const Packet *, bool all=true)
Copy most packet annotations from p.
Definition packet.hh:1156
WritablePacket * push(uint32_t len)
Add space for a header before the packet.
Definition packet.hh:2074
void set_transport_header(const unsigned char *p)
Set the transport header.
Definition packet.hh:2430
WritablePacket * uniqueify()
Return an unshared packet containing this packet's data.
Definition packet.hh:2058
Packet * shift_data(int offset, bool free_on_failure=true)
Shift packet data within the data buffer.
Definition packet.cc:1510
void set_anno_ptr(int i, const void *x)
Set void * sized annotation at offset i.
Definition packet.hh:777
int mac_header_offset() const
Return the offset from the packet data to the MAC header.
Definition packet.hh:2544
void set_ether_header(const click_ether *ethh)
Set the MAC header pointer to an Ethernet header.
Definition packet.hh:2356
const unsigned char * buffer() const
Return a pointer to the packet's data buffer.
Definition packet.hh:1243
void set_network_header_length(uint32_t len)
Set the network header length.
Definition packet.hh:2472
void change_headroom_and_length(uint32_t headroom, uint32_t length)
Shift the packet's data view to a different part of its buffer.
Definition packet.hh:2274
const unsigned char * end_data() const
Return the packet's end data pointer.
Definition packet.hh:1223
void set_device_anno(net_device *dev)
Set the device annotation.
Definition packet.hh:1649
const unsigned char * data() const
Return the packet's data pointer.
Definition packet.hh:1207
static void empty_destructor(unsigned char *, size_t, void *)
Definition packet.cc:1044
int ip_header_offset() const
Return the offset from the packet data to the IP header.
Definition packet.hh:2587
void kill_nonatomic()
Delete this packet in a thread-safe context.
Definition packet.hh:1853
PacketType
Values for packet_type_anno(). Must agree with Linux's PACKET_ constants in <linux/if_packet....
Definition packet.hh:490
@ OTHERHOST
Definition packet.hh:496
@ OUTGOING
Definition packet.hh:499
@ MULTICAST
Definition packet.hh:494
@ HOST
Definition packet.hh:491
@ BROADCAST
Definition packet.hh:492
Packet * clone(bool fast=false)
Create a clone of this packet.
Definition packet.cc:1104
const uint8_t * anno_u8() const
overload
Definition packet.hh:592
uint32_t ip6_header_length() const
Return the IPv6 header length.
Definition packet.hh:2623
uint32_t length() const
Return the packet's length.
Definition packet.hh:1276
int network_header_offset() const
Return the offset from the packet data to the network header.
Definition packet.hh:2565
@ anno_size
Size of annotation area.
Definition packet.hh:472
const click_udp * udp_header() const
Return the packet's transport header pointer as UDP.
Definition packet.hh:1563
void * anno()
Return a pointer to the annotation area.
Definition packet.hh:583
void take(uint32_t len)
Remove space from the end of the packet.
Definition packet.hh:2189
bool has_transport_header() const
Return true iff the packet's transport header pointer is set.
Definition packet.hh:1473
const unsigned char * transport_header() const
Return the packet's transport header pointer.
Definition packet.hh:1495
PacketType packet_type_anno() const
Return the packet type annotation.
Definition packet.hh:1662
void clear_mac_header()
Unset the MAC header pointer.
Definition packet.hh:2365
void set_ip_header(const click_ip *iph, uint32_t len)
Set the network header pointer to an IPv4 header.
Definition packet.hh:2493
bool has_mac_header() const
Return true iff the packet's MAC header pointer is set.
Definition packet.hh:1401
void set_anno_u8(int i, uint8_t x)
Set annotation byte at offset i.
Definition packet.hh:611
IPAddress dst_ip_anno() const
Return the destination IPv4 address annotation.
Definition packet.hh:2300
uint32_t ip_header_length() const
Return the IP header length.
Definition packet.hh:2600
int transport_header_offset() const
Return the offset from the packet data to the transport header.
Definition packet.hh:2632
const Timestamp & timestamp_anno() const
Return the timestamp annotation.
Definition packet.hh:1596
void set_network_header(const unsigned char *p)
Set the network header.
Definition packet.hh:2413
Packet * next() const
Return the next packet annotation.
Definition packet.hh:1327
Packet * nonunique_put(uint32_t len)
Add space for data after the packet.
Definition packet.hh:2169
bool copy(Packet *p, int headroom=0)
Copy the content and annotations of another packet (userlevel) into this packet.
Definition packet.cc:1064
uint32_t headroom() const
Return the packet's headroom.
Definition packet.hh:1293
bool shared() const
Test whether this packet's data is shared.
Definition packet.hh:1985
void clear_annotations(bool all=true)
Clear all packet annotations.
Definition packet.hh:1123
void set_packet_type_anno(PacketType t)
Set the packet type annotation.
Definition packet.hh:1674
int transport_length() const
Return the packet's length starting from its transport header pointer.
Definition packet.hh:1590
bool has_network_header() const
Return true iff the packet's network header pointer is set.
Definition packet.hh:1435
uint32_t buffer_length() const
Return the packet's buffer length.
Definition packet.hh:1321
void clear_network_header()
Unset the network header pointer.
Definition packet.hh:2525
@ default_headroom
Definition packet.hh:82
@ min_buffer_length
Definition packet.hh:85
void set_timestamp_anno(const Timestamp &t)
Set the timestamp annotation.
Definition packet.hh:1628
int mac_length() const
Return the packet's length starting from its MAC header pointer.
Definition packet.hh:1572
void set_prev(Packet *p)
Set the previous packet annotation.
Definition packet.hh:1387
int network_length() const
Return the packet's length starting from its network header pointer.
Definition packet.hh:1581
const uint32_t * anno_u32() const
overload
Definition packet.hh:598
uint32_t network_header_length() const
Return the network header length.
Definition packet.hh:2577
const click_ether * ether_header() const
Return the packet's MAC header pointer as Ethernet.
Definition packet.hh:1513
Represents a moment or interval in time.
Definition timestamp.hh:125
A network packet believed not to be shared.
Definition packet.hh:1004
unsigned char * data() const
Definition packet.hh:2941
static void pool_transfer(int from, int to)
Definition packet.cc:836
void rewrite_ips(IPPair pair, bool is_tcp=true)
Definition packet.hh:3065
A 32-bit integer with support for atomic operations.
Definition atomic.hh:71
The IPAddress type for IPv4 addresses.
The Timestamp class represents a moment or interval in time.