Azinix

pkt.c File Reference

Packet code. More...

#include "pkt.h"

Go to the source code of this file.

Functions

Pkt_IpHdr_tPkt_EthernetExtractIp (Pkt_EthernetHdr_t *ethPkt)
 Extract the Ip component from an Ethernet packet.
int Pkt_EthernetPktHdrReadLengthNetworkOrder (Pkt_EthernetHdr_t *pkt)
 Return the length of the Ethernet packet, including header.
int Pkt_EthernetPktHdrReadLength (Pkt_EthernetHdr_t *pkt)
 Return the length of the Ethernet packet, including header.
int Pkt_EthernetHdrFree (Pkt_EthernetHdr_t *pkt)
 Free an Ethernet packet.
int Pkt_ProcessPktFree (Pkt_ProcessPkt_t *pp)
 Free an ProcessPkt structure.
Pkt_IcmpHdr_tPkt_IpExtractIcmp (Pkt_IpHdr_t *anIpPkt)
 Extract the Icmp component from an Ip packet.
Pkt_UdpHdr_tPkt_IpExtractUdp (Pkt_IpHdr_t *anIpPkt)
 Extract the Udp component from an Ip packet.
Pkt_TcpHdr_tPkt_IpExtractTcp (Pkt_IpHdr_t *anIpPkt)
 Extract the Tcp component from an Ip packet.
char * Pkt_IpExtractPayload (Pkt_IpHdr_t *anIpPkt)
 Extract the payload component from an Ip packet.
Pkt_UdpHdr_tPkt_EthernetExtractUdp (Pkt_EthernetHdr_t *aEthernetPkt)
 Extract the Tcp component from an Ethernet packet.
Pkt_TcpHdr_tPkt_EthernetExtractTcp (Pkt_EthernetHdr_t *aEthernetPkt)
 Extract the Tcp component from an Ethernet packet.
Pkt_IcmpHdr_tPkt_EthernetExtractIcmp (Pkt_EthernetHdr_t *aEthernetPkt)
 Extract the Icmp component from an Ethernet packet.
char * Pkt_UdpHdrReadPayload (Pkt_UdpHdr_t *aUdpPkt)
 Returns a pointer to the payload of a UDP packet.
char * Pkt_TcpHdrReadPayload (Pkt_TcpHdr_t *aTcpPkt)
 Returns a pointer to the payload of a TCP packet.
int Pkt_SrcIpFlowCmp (Pkt_EthernetHdr_t *pkt1, Pkt_EthernetHdr_t *pkt2)
 Compare two src ip flows Returns -1, 0, 1 a la strcmp.
int Pkt_DestIpFlowCmp (Pkt_EthernetHdr_t *pkt1, Pkt_EthernetHdr_t *pkt2)
 Compare two dest ip flows Returns -1, 0 , 1.
int Pkt_SrcDestIpFlowCmp (Pkt_EthernetHdr_t *pkt1, Pkt_EthernetHdr_t *pkt2)
 Compare two src-dest ip flows Returns -1,0,1 a la strcmp.
int Pkt_DestTcpIpFlowCmp (Pkt_EthernetHdr_t *pkt1, Pkt_EthernetHdr_t *pkt2)
 Compare two dest tcp-Ip flows. Returns -1, 0, 1 a la strcmp.
int Pkt_SrcIpFlowHash (Pkt_EthernetHdr_t *pkt1, int modulus)
 Hash a src-ip flow.
int Pkt_DestIpFlowHash (Pkt_EthernetHdr_t *pkt1, int modulus)
 Hash a dest-ip.
int Pkt_SrcDestIpFlowHash (Pkt_EthernetHdr_t *pkt1, int modulus)
 Hash a src-dest ip flow.
int Pkt_DestTcpIpFlowHash (Pkt_EthernetHdr_t *pkt1, int modulus)
 Hash a dest tcp-Ip flow.
int Pkt_SrcDestTcpIpFlowHash (Pkt_EthernetHdr_t *pkt1, int modulus)
 Hash a tcp-Ip flow.
int Pkt_SrcDestTcpIpFlowCmp (Pkt_EthernetHdr_t *pkt1, Pkt_EthernetHdr_t *pkt2)
 Compare two Tcp-Ip flows. Returns -1, 0, 1 a la strcmp.
int Pkt_L4FlowCompareForSt (Pkt_L4Flow_t *foo, Pkt_L4Flow_t *bar)
 Compare function for an L4 flow struct for the st package, returns 0 for equal, 1 for unequal.
int Pkt_L4FlowCompare (Pkt_L4Flow_t *foo, Pkt_L4Flow_t *bar)
 Compare function for an L4 flow struct - 1 for equal, 0 for unequal.
int Pkt_L4FlowHashForSt (Pkt_L4Flow_t *anL4FlowStruct, int modulus)
 Hash function for an L4 flow struct with modulus argument.
unsigned int Pkt_L4FlowHash (Pkt_L4Flow_t *anL4FlowStruct)
 Hash function for an L4 flow struct.
Pkt_L4Flow_tPkt_EthPktToL4Flow (Pkt_EthernetHdr_t *anEthPkt)
 Create a L4 flow structure from an Ethernet packet.
Pkt_L4Flow_tPkt_IpPktToL4Flow (Pkt_IpHdr_t *anIpPkt)
 Create a L4 flow structure from an Ip packet.
int Pkt_EthernetReadL3Type (Pkt_EthernetHdr_t *anEth)
 Return the L3 type of an ethernet packet.
int Pkt_PrintEthernet (Pkt_EthernetHdr_t *anEthPkt, int length)
 Print an Ethernet packet.
int Pkt_PrintWifi (Pkt_WifiHdr_t *aWifiPkt)
 Print a Wifi packet.
int Pkt_PrintIp (Pkt_IpHdr_t *anIpPkt)
 Print an Ip Pkt, given in network order.
void Pkt_PrintIpAddressDotted (u_int32_t aNumIp)
 Print an Ip address in 1.2.3.4 format.
void Pkt_PrintIpAddressDottedGeneral (char *buf, u_int32_t aNumIp)
 Print an Ip address in 1.2.3.4 format.
Pkt_ProcessPkt_tPkt_AllocateProcessPacket (Pkt_EthernetHdr_t *pkt, array_t *applicableRules)
 Allocate a process-packet structure.


Detailed Description

Packet code.

Definition in file pkt.c.


Function Documentation

Pkt_ProcessPkt_t* Pkt_AllocateProcessPacket ( Pkt_EthernetHdr_t pkt,
array_t applicableRules 
)

Allocate a process-packet structure.

Definition at line 790 of file pkt.c.

int Pkt_DestIpFlowCmp ( Pkt_EthernetHdr_t pkt1,
Pkt_EthernetHdr_t pkt2 
)

Compare two dest ip flows Returns -1, 0 , 1.

Definition at line 280 of file pkt.c.

int Pkt_DestIpFlowHash ( Pkt_EthernetHdr_t pkt1,
int  modulus 
)

Hash a dest-ip.

Definition at line 392 of file pkt.c.

int Pkt_DestTcpIpFlowCmp ( Pkt_EthernetHdr_t pkt1,
Pkt_EthernetHdr_t pkt2 
)

Compare two dest tcp-Ip flows. Returns -1, 0, 1 a la strcmp.

Definition at line 335 of file pkt.c.

int Pkt_DestTcpIpFlowHash ( Pkt_EthernetHdr_t pkt1,
int  modulus 
)

Hash a dest tcp-Ip flow.

Definition at line 431 of file pkt.c.

Pkt_IcmpHdr_t* Pkt_EthernetExtractIcmp ( Pkt_EthernetHdr_t aEthernetPkt  ) 

Extract the Icmp component from an Ethernet packet.

No new memory is allocated, simply returning a pointer.

Definition at line 215 of file pkt.c.

Pkt_IpHdr_t* Pkt_EthernetExtractIp ( Pkt_EthernetHdr_t ethPkt  ) 

Extract the Ip component from an Ethernet packet.

No new memory is allocated, simply returning a pointer. Note that we're being careless with the difference between an actual packet, and just the header.

Definition at line 27 of file pkt.c.

Pkt_TcpHdr_t* Pkt_EthernetExtractTcp ( Pkt_EthernetHdr_t aEthernetPkt  ) 

Extract the Tcp component from an Ethernet packet.

No new memory is allocated, simply returning a pointer.

Definition at line 200 of file pkt.c.

Pkt_UdpHdr_t* Pkt_EthernetExtractUdp ( Pkt_EthernetHdr_t aEthernetPkt  ) 

Extract the Tcp component from an Ethernet packet.

No new memory is allocated, simply returning a pointer.

Definition at line 185 of file pkt.c.

int Pkt_EthernetHdrFree ( Pkt_EthernetHdr_t pkt  ) 

Free an Ethernet packet.

Assumes packet was allocated by malloc

Definition at line 82 of file pkt.c.

int Pkt_EthernetPktHdrReadLength ( Pkt_EthernetHdr_t pkt  ) 

Return the length of the Ethernet packet, including header.

Only IP suppored for now

Definition at line 62 of file pkt.c.

int Pkt_EthernetPktHdrReadLengthNetworkOrder ( Pkt_EthernetHdr_t pkt  ) 

Return the length of the Ethernet packet, including header.

Only IP suppored for now. Packet is assumed to be in network order.

Definition at line 41 of file pkt.c.

int Pkt_EthernetReadL3Type ( Pkt_EthernetHdr_t anEth  ) 

Return the L3 type of an ethernet packet.

Promotes a short to an int in the process.

Definition at line 637 of file pkt.c.

Pkt_L4Flow_t* Pkt_EthPktToL4Flow ( Pkt_EthernetHdr_t anEthPkt  ) 

Create a L4 flow structure from an Ethernet packet.

Definition at line 599 of file pkt.c.

Pkt_IcmpHdr_t* Pkt_IpExtractIcmp ( Pkt_IpHdr_t anIpPkt  ) 

Extract the Icmp component from an Ip packet.

No new memory is allocated, simply returning a pointer. Note that we're being careless with the difference between an actual packet, and just the header. If the encapsulated packet is not ip encapsualting icmp we return NIL.

Definition at line 114 of file pkt.c.

char* Pkt_IpExtractPayload ( Pkt_IpHdr_t anIpPkt  ) 

Extract the payload component from an Ip packet.

No new memory is allocated, simply returning a pointer.

Definition at line 169 of file pkt.c.

Pkt_TcpHdr_t* Pkt_IpExtractTcp ( Pkt_IpHdr_t anIpPkt  ) 

Extract the Tcp component from an Ip packet.

No new memory is allocated, simply returning a pointer.

Definition at line 154 of file pkt.c.

Pkt_UdpHdr_t* Pkt_IpExtractUdp ( Pkt_IpHdr_t anIpPkt  ) 

Extract the Udp component from an Ip packet.

No new memory is allocated, simply returning a pointer.

Definition at line 134 of file pkt.c.

Pkt_L4Flow_t* Pkt_IpPktToL4Flow ( Pkt_IpHdr_t anIpPkt  ) 

Create a L4 flow structure from an Ip packet.

Definition at line 613 of file pkt.c.

int Pkt_L4FlowCompare ( Pkt_L4Flow_t foo,
Pkt_L4Flow_t bar 
)

Compare function for an L4 flow struct - 1 for equal, 0 for unequal.

Definition at line 545 of file pkt.c.

int Pkt_L4FlowCompareForSt ( Pkt_L4Flow_t foo,
Pkt_L4Flow_t bar 
)

Compare function for an L4 flow struct for the st package, returns 0 for equal, 1 for unequal.

Definition at line 529 of file pkt.c.

unsigned int Pkt_L4FlowHash ( Pkt_L4Flow_t anL4FlowStruct  ) 

Hash function for an L4 flow struct.

See also:
st_strhash

Definition at line 580 of file pkt.c.

int Pkt_L4FlowHashForSt ( Pkt_L4Flow_t anL4FlowStruct,
int  modulus 
)

Hash function for an L4 flow struct with modulus argument.

Definition at line 561 of file pkt.c.

int Pkt_PrintEthernet ( Pkt_EthernetHdr_t anEthPkt,
int  length 
)

Print an Ethernet packet.

Packet is assumed to be in network format.

Definition at line 650 of file pkt.c.

int Pkt_PrintIp ( Pkt_IpHdr_t anIpPkt  ) 

Print an Ip Pkt, given in network order.

Definition at line 727 of file pkt.c.

void Pkt_PrintIpAddressDotted ( u_int32_t  aNumIp  ) 

Print an Ip address in 1.2.3.4 format.

Definition at line 754 of file pkt.c.

void Pkt_PrintIpAddressDottedGeneral ( char *  buf,
u_int32_t  aNumIp 
)

Print an Ip address in 1.2.3.4 format.

Definition at line 764 of file pkt.c.

int Pkt_PrintWifi ( Pkt_WifiHdr_t aWifiPkt  ) 

Print a Wifi packet.

Definition at line 694 of file pkt.c.

int Pkt_ProcessPktFree ( Pkt_ProcessPkt_t pp  ) 

Free an ProcessPkt structure.

Does not free the packet, but does free applicable rules.

Definition at line 96 of file pkt.c.

int Pkt_SrcDestIpFlowCmp ( Pkt_EthernetHdr_t pkt1,
Pkt_EthernetHdr_t pkt2 
)

Compare two src-dest ip flows Returns -1,0,1 a la strcmp.

Definition at line 303 of file pkt.c.

int Pkt_SrcDestIpFlowHash ( Pkt_EthernetHdr_t pkt1,
int  modulus 
)

Hash a src-dest ip flow.

Definition at line 411 of file pkt.c.

int Pkt_SrcDestTcpIpFlowCmp ( Pkt_EthernetHdr_t pkt1,
Pkt_EthernetHdr_t pkt2 
)

Compare two Tcp-Ip flows. Returns -1, 0, 1 a la strcmp.

Definition at line 478 of file pkt.c.

int Pkt_SrcDestTcpIpFlowHash ( Pkt_EthernetHdr_t pkt1,
int  modulus 
)

Hash a tcp-Ip flow.

Definition at line 453 of file pkt.c.

int Pkt_SrcIpFlowCmp ( Pkt_EthernetHdr_t pkt1,
Pkt_EthernetHdr_t pkt2 
)

Compare two src ip flows Returns -1, 0, 1 a la strcmp.

See also:
st_init_table

Definition at line 256 of file pkt.c.

int Pkt_SrcIpFlowHash ( Pkt_EthernetHdr_t pkt1,
int  modulus 
)

Hash a src-ip flow.

Definition at line 372 of file pkt.c.

char* Pkt_TcpHdrReadPayload ( Pkt_TcpHdr_t aTcpPkt  ) 

Returns a pointer to the payload of a TCP packet.

Definition at line 241 of file pkt.c.

char* Pkt_UdpHdrReadPayload ( Pkt_UdpHdr_t aUdpPkt  ) 

Returns a pointer to the payload of a UDP packet.

Definition at line 229 of file pkt.c.