All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Functions | Variables
net.c File Reference

Functions to parse raw packets. More...

#include <freeradius-devel/libradius.h>
#include <freeradius-devel/net.h>
+ Include dependency graph for net.c:

Go to the source code of this file.

Functions

uint16_t fr_ip_header_checksum (uint8_t const *data, uint8_t ihl)
 Calculate IP header checksum. More...
 
ssize_t fr_link_layer_offset (uint8_t const *data, size_t len, int link_layer)
 Returns the length of the link layer header. More...
 
bool fr_link_layer_supported (int link_layer)
 Check whether fr_link_layer_offset can process a link_layer. More...
 
uint16_t fr_udp_checksum (uint8_t const *data, uint16_t len, uint16_t checksum, struct in_addr const src_addr, struct in_addr const dst_addr)
 Calculate UDP checksum. More...
 
int fr_udp_header_check (uint8_t const *data, uint16_t remaining, ip_header_t const *ip)
 Check UDP header is valid. More...
 

Variables

FR_NAME_NUMBER const fr_net_af_table []
 Strings for address families. More...
 
FR_NAME_NUMBER const fr_net_ip_proto_table []
 Strings for L4 protocols. More...
 
FR_NAME_NUMBER const fr_net_sock_type_table []
 Strings for socket types. More...
 

Detailed Description

Functions to parse raw packets.

Id:
2beaeea6ff911d12ac7800070141e40edd91c96f
Author
Arran Cudbard-Bell a.cud.nosp@m.bard.nosp@m.b@fre.nosp@m.erad.nosp@m.ius.o.nosp@m.rg

Definition in file net.c.

Function Documentation

uint16_t fr_ip_header_checksum ( uint8_t const *  data,
uint8_t  ihl 
)

Calculate IP header checksum.

Zero out IP header checksum in IP header before calling fr_ip_header_checksum to get 'expected' checksum.

Parameters
dataPointer to the start of the IP header
ihlvalue of ip header length field (number of 32 bit words)

Definition at line 275 of file net.c.

ssize_t fr_link_layer_offset ( uint8_t const *  data,
size_t  len,
int  link_layer 
)

Returns the length of the link layer header.

Libpcap does not include a decoding function to skip the L2 header, but it does at least inform us of the type.

Unfortunately some headers are of variable length (like ethernet), so additional decoding logic is required.

Note
No header data is returned, this is only meant to be used to determine how data to consume before attempting to parse the IP header.
Parameters
datastart of packet data.
lencaplen.
link_layervalue returned from pcap_linktype.
Returns
  • Length of the header.
  • -1 on failure.

Definition at line 95 of file net.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool fr_link_layer_supported ( int  link_layer)

Check whether fr_link_layer_offset can process a link_layer.

Parameters
link_layerto check.
Returns
  • true if supported.
  • false if not supported.

Definition at line 61 of file net.c.

+ Here is the caller graph for this function:

uint16_t fr_udp_checksum ( uint8_t const *  data,
uint16_t  len,
uint16_t  checksum,
struct in_addr const  src_addr,
struct in_addr const  dst_addr 
)

Calculate UDP checksum.

Zero out UDP checksum in UDP header before calling fr_udp_checksum to get 'expected' checksum.

Parameters
dataPointer to the start of the UDP header
lenvalue of udp length field in host byte order. Must be validated to make sure it won't overrun data buffer.
checksumcurrent checksum, leave as 0 to just enable validation.
src_addrin network byte order.
dst_addrin network byte order.
Returns
  • 0 if the checksum is correct.
  • !0 if checksum is incorrect.

Definition at line 240 of file net.c.

+ Here is the caller graph for this function:

int fr_udp_header_check ( uint8_t const *  data,
uint16_t  remaining,
ip_header_t const *  ip 
)

Check UDP header is valid.

Parameters
dataPointer to the start of the UDP header
remainingbits of received packet
ippointer to IP header structure
Returns
  • 1 if checksum is incorrect.
  • 0 if UDP payload lenght and checksum are correct
  • -1 on validation error.

Definition at line 186 of file net.c.

+ Here is the call graph for this function:

Variable Documentation

FR_NAME_NUMBER const fr_net_af_table[]
Initial value:
= {
{ "IPv4", AF_INET },
{ "IPv6", AF_INET6 },
{ NULL, 0 }
}

Strings for address families.

Definition at line 48 of file net.c.

FR_NAME_NUMBER const fr_net_ip_proto_table[]
Initial value:
= {
{ "UDP", IPPROTO_UDP },
{ "TCP", IPPROTO_TCP },
{ NULL, 0 }
}

Strings for L4 protocols.

Definition at line 30 of file net.c.

FR_NAME_NUMBER const fr_net_sock_type_table[]
Initial value:
= {
{ "UDP", SOCK_DGRAM },
{ "TCP", SOCK_STREAM },
{ NULL, 0 }
}

Strings for socket types.

Definition at line 39 of file net.c.