The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Functions | Variables
net.c File Reference

Functions for parsing raw network packets. More...

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

Go to the source code of this file.

Functions

uint16_t fr_ip6_pesudo_header_checksum (struct in6_addr const *src, struct in6_addr const *dst, uint16_t ip_len, uint8_t ip_next)
 
uint16_t fr_ip_header_checksum (uint8_t const *data, uint8_t ihl)
 Calculate IP header checksum. 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_table_num_sorted_t const fr_net_af_table []
 Strings for address families. More...
 
size_t fr_net_af_table_len = NUM_ELEMENTS(fr_net_af_table)
 
fr_table_num_sorted_t const fr_net_ip_proto_table []
 Strings for L4 protocols. More...
 
size_t fr_net_ip_proto_table_len = NUM_ELEMENTS(fr_net_ip_proto_table)
 
fr_table_num_sorted_t const fr_net_sock_type_table []
 Strings for socket types. More...
 
size_t fr_net_sock_type_table_len = NUM_ELEMENTS(fr_net_sock_type_table)
 

Detailed Description

Functions for parsing raw network packets.

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

◆ fr_ip6_pesudo_header_checksum()

uint16_t fr_ip6_pesudo_header_checksum ( struct in6_addr const *  src,
struct in6_addr const *  dst,
uint16_t  ip_len,
uint8_t  ip_next 
)

Definition at line 169 of file net.c.

+ Here is the caller graph for this function:

◆ fr_ip_header_checksum()

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 154 of file net.c.

◆ fr_udp_checksum()

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 119 of file net.c.

+ Here is the caller graph for this function:

◆ fr_udp_header_check()

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 length and checksum are correct
  • -1 on validation error.

Definition at line 64 of file net.c.

+ Here is the call graph for this function:

Variable Documentation

◆ fr_net_af_table

fr_table_num_sorted_t const fr_net_af_table[]
Initial value:
= {
{ L("IPv4"), AF_INET },
{ L("IPv6"), AF_INET6 }
}
#define L(_str)
Helper for initialising arrays of string literals.
Definition: build.h:207

Strings for address families.

Definition at line 48 of file net.c.

◆ fr_net_af_table_len

size_t fr_net_af_table_len = NUM_ELEMENTS(fr_net_af_table)

Definition at line 52 of file net.c.

◆ fr_net_ip_proto_table

fr_table_num_sorted_t const fr_net_ip_proto_table[]
Initial value:
= {
{ L("ICMP"), IPPROTO_ICMP },
{ L("ICMPv6"), IPPROTO_ICMPV6 },
{ L("TCP"), IPPROTO_TCP },
{ L("UDP"), IPPROTO_UDP }
}

Strings for L4 protocols.

Definition at line 28 of file net.c.

◆ fr_net_ip_proto_table_len

size_t fr_net_ip_proto_table_len = NUM_ELEMENTS(fr_net_ip_proto_table)

Definition at line 34 of file net.c.

◆ fr_net_sock_type_table

fr_table_num_sorted_t const fr_net_sock_type_table[]
Initial value:
= {
{ L("TCP"), SOCK_STREAM },
{ L("UDP"), SOCK_DGRAM }
}

Strings for socket types.

Definition at line 39 of file net.c.

◆ fr_net_sock_type_table_len

size_t fr_net_sock_type_table_len = NUM_ELEMENTS(fr_net_sock_type_table)

Definition at line 43 of file net.c.