Click
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
WritablePacket Class Reference

A network packet believed not to be shared. More...

Inheritance diagram for WritablePacket:
Packet

Public Member Functions

unsigned char * data () const
 
unsigned char * end_data () const
 
unsigned char * buffer () const
 
unsigned char * end_buffer () const
 
unsigned char * mac_header () const
 
click_ether * ether_header () const
 
unsigned char * network_header () const
 
click_ip * ip_header () const
 
click_ip6 * ip6_header () const
 
unsigned char * transport_header () const
 
click_icmp * icmp_header () const
 
click_tcp * tcp_header () const
 
click_udp * udp_header () const
 
unsigned char * getPacketContent ()
 
void rewrite_ips (IPPair pair, bool is_tcp=true)
 
void rewrite_ips_ports (IPPair pair, uint16_t sport, uint16_t dport, bool is_tcp=true)
 
void rewrite_ipport (IPAddress ip, uint16_t port, const int shift, bool is_tcp=true)
 
void rewrite_ip (IPAddress ip, const int shift, bool is_tcp=true)
 
void rewrite_seq (tcp_seq_t seq, const int shift)
 
WritablePacket * unique_next ()
 
WritablePacket * unique_prev ()
 
 WritablePacket (const Packet &x)
 
- Public Member Functions inherited from Packet
void kill ()
 Delete this packet.
 
void kill_nonatomic ()
 Delete this packet in a thread-safe context.
 
bool shared () const
 Test whether this packet's data is shared.
 
bool shared_nonatomic () const
 Test whether this packet's data is shared.
 
Packet * clone (bool fast=false)
 Create a clone of this packet.
 
WritablePacket * duplicate (int32_t extra_headroom=0, int32_t extra_tailroom=0, const bool data_only=true)
 
WritablePacket * uniqueify ()
 Return an unshared packet containing this packet's data.
 
void get ()
 
const unsigned char * data () const
 Return the packet's data pointer.
 
const unsigned char * end_data () const
 Return the packet's end data pointer.
 
uint32_t length () const
 Return the packet's length.
 
uint32_t headroom () const
 Return the packet's headroom.
 
uint32_t tailroom () const
 Return the packet's tailroom.
 
const unsigned char * buffer () const
 Return a pointer to the packet's data buffer.
 
const unsigned char * end_buffer () const
 Return the packet's end data buffer pointer.
 
uint32_t buffer_length () const
 Return the packet's buffer length.
 
struct sk_buff * skb ()
 
const struct sk_buff * skb () const
 
WritablePacket * push (uint32_t len)
 Add space for a header before the packet.
 
WritablePacket * push_mac_header (uint32_t len)
 Add space for a MAC header before the packet.
 
Packet * nonunique_push (uint32_t len)
 Add space for a header before the packet.
 
void pull (uint32_t len)
 Remove a header from the front of the packet.
 
WritablePacket * put (uint32_t len)
 Add space for data after the packet.
 
Packet * nonunique_put (uint32_t len)
 Add space for data after the packet.
 
void take (uint32_t len)
 Remove space from the end of the packet.
 
Packet * shift_data (int offset, bool free_on_failure=true)
 Shift packet data within the data buffer.
 
void shrink_data (const unsigned char *data, uint32_t length)
 Shrink the packet's data.
 
void change_headroom_and_length (uint32_t headroom, uint32_t length)
 Shift the packet's data view to a different part of its buffer.
 
void change_buffer_length (uint32_t length)
 
bool copy (Packet *p, int headroom=0)
 Copy the content and annotations of another packet (userlevel) into this packet.
 
const Timestamp & timestamp_anno () const
 Return the timestamp annotation.
 
Timestamp & timestamp_anno ()
 
void set_timestamp_anno (const Timestamp &t)
 Set the timestamp annotation.
 
net_device * device_anno () const
 Return the device annotation.
 
void set_device_anno (net_device *dev)
 Set the device annotation.
 
PacketType packet_type_anno () const
 Return the packet type annotation.
 
void set_packet_type_anno (PacketType t)
 Set the packet type annotation.
 
Packet * next () const
 Return the next packet annotation.
 
Packet *& next ()
 
void set_next (Packet *p)
 Set the next packet annotation.
 
Packet * prev () const
 Return the previous packet annotation.
 
Packet *& prev ()
 
void set_prev (Packet *p)
 Set the previous packet annotation.
 
Packet * find_tail ()
 
unsigned int find_count ()
 
IPAddress dst_ip_anno () const
 Return the destination IPv4 address annotation.
 
void set_dst_ip_anno (IPAddress addr)
 Set the destination IPv4 address annotation.
 
void * anno ()
 Return a pointer to the annotation area.
 
const void * anno () const
 
uint8_t * anno_u8 ()
 Return a pointer to the annotation area as uint8_ts.
 
const uint8_t * anno_u8 () const
 overload
 
uint32_t * anno_u32 ()
 Return a pointer to the annotation area as uint32_ts.
 
const uint32_t * anno_u32 () const
 overload
 
uint8_t anno_u8 (int i) const
 Return annotation byte at offset i.
 
void set_anno_u8 (int i, uint8_t x)
 Set annotation byte at offset i.
 
uint16_t anno_u16 (int i) const
 Return 16-bit annotation at offset i.
 
void set_anno_u16 (int i, uint16_t x)
 Set 16-bit annotation at offset i.
 
int16_t anno_s16 (int i) const
 Return 16-bit annotation at offset i.
 
void set_anno_s16 (int i, int16_t x)
 Set 16-bit annotation at offset i.
 
uint32_t anno_u32 (int i) const
 Return 32-bit annotation at offset i.
 
void set_anno_u32 (int i, uint32_t x)
 Set 32-bit annotation at offset i.
 
int32_t anno_s32 (int i) const
 Return 32-bit annotation at offset i.
 
void set_anno_s32 (int i, int32_t x)
 Set 32-bit annotation at offset i.
 
uint64_t anno_u64 (int i) const
 Return 64-bit annotation at offset i.
 
void set_anno_u64 (int i, uint64_t x)
 Set 64-bit annotation at offset i.
 
void * anno_ptr (int i) const
 Return void * sized annotation at offset i.
 
void set_anno_ptr (int i, const void *x)
 Set void * sized annotation at offset i.
 
Packet * data_packet ()
 
void clear_annotations (bool all=true)
 Clear all packet annotations.
 
void copy_annotations (const Packet *, bool all=true)
 Copy most packet annotations from p.
 
void copy_headers (const Packet *)
 
bool has_mac_header () const
 Return true iff the packet's MAC header pointer is set.
 
const unsigned char * mac_header () const
 Return the packet's MAC header pointer.
 
int mac_header_offset () const
 Return the offset from the packet data to the MAC header.
 
uint32_t mac_header_length () const
 Return the MAC header length.
 
int mac_length () const
 Return the packet's length starting from its MAC header pointer.
 
void set_mac_header (const unsigned char *p)
 Set the MAC header pointer.
 
void set_mac_header (const unsigned char *p, uint32_t len)
 Set the MAC and network header pointers.
 
void clear_mac_header ()
 Unset the MAC header pointer.
 
bool has_network_header () const
 Return true iff the packet's network header pointer is set.
 
const unsigned char * network_header () const
 Return the packet's network header pointer.
 
int network_header_offset () const
 Return the offset from the packet data to the network header.
 
uint32_t network_header_length () const
 Return the network header length.
 
int network_length () const
 Return the packet's length starting from its network header pointer.
 
void set_network_header (const unsigned char *p)
 Set the network header.
 
void set_network_header (const unsigned char *p, uint32_t len)
 Set the network and transport header pointers.
 
void set_network_header_length (uint32_t len)
 Set the network header length.
 
void clear_network_header ()
 Unset the network header pointer.
 
void set_transport_header (const unsigned char *p)
 Set the transport header.
 
bool has_transport_header () const
 Return true iff the packet's transport header pointer is set.
 
const unsigned char * transport_header () const
 Return the packet's transport header pointer.
 
int transport_header_offset () const
 Return the offset from the packet data to the transport header.
 
int transport_length () const
 Return the packet's length starting from its transport header pointer.
 
void clear_transport_header ()
 Unset the transport header pointer.
 
const click_ether * ether_header () const
 Return the packet's MAC header pointer as Ethernet.
 
void set_ether_header (const click_ether *ethh)
 Set the MAC header pointer to an Ethernet header.
 
const click_ip * ip_header () const
 Return the packet's network header pointer as IPv4.
 
int ip_header_offset () const
 Return the offset from the packet data to the IP header.
 
uint32_t ip_header_length () const
 Return the IP header length.
 
void set_ip_header (const click_ip *iph, uint32_t len)
 Set the network header pointer to an IPv4 header.
 
const click_ip6 * ip6_header () const
 Return the packet's network header pointer as IPv6.
 
int ip6_header_offset () const
 Return the offset from the packet data to the IPv6 header.
 
uint32_t ip6_header_length () const
 Return the IPv6 header length.
 
void set_ip6_header (const click_ip6 *ip6h)
 Set the network header pointer to an IPv6 header.
 
void set_ip6_header (const click_ip6 *ip6h, uint32_t len)
 Set the network header pointer to an IPv6 header.
 
const click_icmp * icmp_header () const
 Return the packet's transport header pointer as ICMP.
 
const click_tcp * tcp_header () const
 Return the packet's transport header pointer as TCP.
 
const click_udp * udp_header () const
 Return the packet's transport header pointer as UDP.
 
uint16_t getContentOffset () const
 
void setContentOffset (uint16_t offset)
 
const unsigned char * getPacketContent ()
 
bool isPacketContentEmpty () const
 
uint16_t getPacketContentSize () const
 

Static Public Member Functions

static void pool_transfer (int from, int to)
 
static WritablePacket * pool_prepare_data_burst (uint16_t count)
 
static void pool_consumed_data_burst (uint16_t n, WritablePacket *tail)
 
- Static Public Member Functions inherited from Packet
static WritablePacket * make (uint32_t headroom, const void *data, uint32_t length, uint32_t tailroom, bool clear=true)
 Create and return a new packet.
 
static WritablePacket * make (const void *data, uint32_t length)
 Create and return a new packet.
 
static WritablePacket * make (uint32_t length)
 Create and return a new packet.
 
static WritablePacket * make_similar (Packet *original, uint32_t length)
 
static Packet * make (struct sk_buff *skb)
 Change an sk_buff into a Packet (linuxmodule).
 
static void empty_destructor (unsigned char *, size_t, void *)
 
static WritablePacket * make (unsigned char *data, uint32_t length, buffer_destructor_type buffer_destructor, void *argument=(void *) 0, int headroom=0, int tailroom=0, bool clear=true)
 Create and return a new packet (userlevel).
 
static int max_data_pool_size ()
 
static void static_cleanup ()
 

Additional Inherited Members

- Public Types inherited from Packet
enum  { default_headroom = 28 , min_buffer_length = 64 }
 
typedef void(* buffer_destructor_type) (unsigned char *buf, size_t sz, void *argument)
 
enum  { anno_size = 48 }
 
enum  PacketType {
  HOST = 0 , BROADCAST = 1 , MULTICAST = 2 , OTHERHOST = 3 ,
  OUTGOING = 4 , LOOPBACK = 5 , FASTROUTE = 6
}
 Values for packet_type_anno(). Must agree with Linux's PACKET_ constants in <linux/if_packet.h>. More...
 
enum  { dst_ip_anno_offset = 0 , dst_ip_anno_size = 4 , dst_ip6_anno_offset = 0 , dst_ip6_anno_size = 16 }
 
- Protected Member Functions inherited from Packet
typedef typeof (((struct sk_buff *) 0) ->mac_header) mac_header_type
 
typedef typeof (((struct sk_buff *) 0) ->network_header) network_header_type
 
typedef typeof (((struct sk_buff *) 0) ->transport_header) transport_header_type
 

Detailed Description

A network packet believed not to be shared.

The WritablePacket type represents Packet objects whose data buffers are not shared. As a result, WritablePacket's versions of functions that access the packet data buffer, such as data(), end_buffer(), and ip_header(), return mutable pointers (char * rather than const char *).

WritablePacket objects are created by Packet::make(), Packet::uniqueify(), Packet::push(), and Packet::put(), which ensure that the returned packet does not share its data buffer.

WritablePacket's interface is the same as Packet's except for these type differences. For documentation, see Packet.

Warning
The WritablePacket convention reduces the likelihood of error when modifying packet data, but does not eliminate it. For instance, by calling WritablePacket::clone(), it is possible to create a WritablePacket whose data is shared:
Packet *p = ...;
if (WritablePacket *q = p->uniqueify()) {
Packet *p2 = q->clone();
assert(p2);
q->ip_header()->ip_v = 6; // modifies p2's data as well
}
A network packet.
Definition packet.hh:68
WritablePacket * uniqueify()
Return an unshared packet containing this packet's data.
Definition packet.hh:2058
Packet * clone(bool fast=false)
Create a clone of this packet.
Definition packet.cc:1104
A network packet believed not to be shared.
Definition packet.hh:1004
Avoid writing buggy code like this! Use WritablePacket selectively, and try to avoid calling WritablePacket::clone() when possible.

Member Function Documentation

◆ data()

unsigned char * WritablePacket::data ( ) const
inline

never

◆ rewrite_ips()

void WritablePacket::rewrite_ips ( IPPair  pair,
bool  is_tcp = true 
)
inline

never

◆ pool_transfer()

void WritablePacket::pool_transfer ( int  from,
int  to 
)
static

Give a hint that some packets from one thread will switch to another thread


The documentation for this class was generated from the following files: