The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Enumerations | Functions | Variables
net.h File Reference

Structures and functions for parsing raw network packets. More...

#include <freeradius-devel/build.h>
#include <freeradius-devel/ethernet/ethernet.h>
#include <freeradius-devel/missing.h>
#include <freeradius-devel/util/hash.h>
#include <freeradius-devel/util/misc.h>
#include <freeradius-devel/util/strerror.h>
#include <freeradius-devel/util/table.h>
#include <netinet/in.h>
#include <stdint.h>
#include <sys/socket.h>
+ Include dependency graph for net.h:

Go to the source code of this file.

Data Structures

struct  ip_header6_t
 
struct  ip_header_t
 
struct  ip_pseudo_header6_t
 
struct  udp_header_t
 

Macros

#define ETHER_ADDR_LEN   6
 
#define ETHER_HDR_LEN   22
 
#define I_DF   0x4000
 Dont fragment flag. More...
 
#define IP_HDR_LEN   60
 
#define IP_HL(ip)   (((ip)->ip_vhl & 0x0f) << 2)
 
#define IP_MF   0x2000
 More fragments flag. More...
 
#define IP_OFFMASK   0x1fff
 Mask for fragmenting bits. More...
 
#define IP_V(ip)   (((ip)->ip_vhl & 0xf0) >> 4)
 
#define IP_VHL(v, hl)   ((v & 0x0f) << 4) | (hl & 0x0f)
 
#define MAX_RADIUS_LEN   4096
 
#define MIN_RADIUS_LEN   20
 
#define RADIUS_AUTH_VECTOR_LENGTH   16
 
#define RADIUS_HEADER_LENGTH   20
 

Enumerations

enum  fr_dlt {
  DLT_RAW ,
  DLT_NULL ,
  DLT_LOOP ,
  DLT_EN10MB ,
  DLT_LINUX_SLL ,
  DLT_PFLOG
}
 

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
 
fr_table_num_sorted_t const fr_net_ip_proto_table []
 Strings for L4 protocols. More...
 
size_t fr_net_ip_proto_table_len
 
fr_table_num_sorted_t const fr_net_sock_type_table []
 Strings for socket types. More...
 
size_t fr_net_sock_type_table_len
 

Detailed Description

Structures and 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.h.


Data Structure Documentation

◆ ip_header6_t

struct ip_header6_t

Definition at line 118 of file net.h.

Data Fields
struct in6_addr ip_src ip_dst Src and Dst address.
uint8_t ip_hopl IP Hop Limit.
uint16_t ip_len Payload length.
uint8_t ip_next Next header (protocol)
uint32_t ip_vtcfl Version, traffic class, flow label.

◆ ip_header_t

struct ip_header_t

Definition at line 104 of file net.h.

Data Fields
struct in_addr ip_src ip_dst Src and Dst address.
uint16_t ip_id identification.
uint16_t ip_len Total length.
uint16_t ip_off Fragment offset field.
uint8_t ip_p Protocol.
uint16_t ip_sum Checksum.
uint8_t ip_tos Type of service.
uint8_t ip_ttl Time To Live.
uint8_t ip_vhl Header length, version.

◆ ip_pseudo_header6_t

struct ip_pseudo_header6_t

Definition at line 128 of file net.h.

Data Fields
struct in6_addr ip_src ip_dst Src and Dst address.
uint32_t ip_len length
uint32_t ip_next upper 24 bits must be zero

◆ udp_header_t

struct udp_header_t

Definition at line 138 of file net.h.

Data Fields
uint16_t checksum UDP checksum.
uint16_t dst Destination port.
uint16_t len UDP length.
uint16_t src Source port.

Macro Definition Documentation

◆ ETHER_ADDR_LEN

#define ETHER_ADDR_LEN   6

Definition at line 64 of file net.h.

◆ ETHER_HDR_LEN

#define ETHER_HDR_LEN   22

Definition at line 74 of file net.h.

◆ I_DF

#define I_DF   0x4000

Dont fragment flag.

Definition at line 97 of file net.h.

◆ IP_HDR_LEN

#define IP_HDR_LEN   60

Definition at line 75 of file net.h.

◆ IP_HL

#define IP_HL (   ip)    (((ip)->ip_vhl & 0x0f) << 2)

Definition at line 93 of file net.h.

◆ IP_MF

#define IP_MF   0x2000

More fragments flag.

Definition at line 98 of file net.h.

◆ IP_OFFMASK

#define IP_OFFMASK   0x1fff

Mask for fragmenting bits.

Definition at line 99 of file net.h.

◆ IP_V

#define IP_V (   ip)    (((ip)->ip_vhl & 0xf0) >> 4)

Definition at line 92 of file net.h.

◆ IP_VHL

#define IP_VHL (   v,
  hl 
)    ((v & 0x0f) << 4) | (hl & 0x0f)

Definition at line 95 of file net.h.

◆ MAX_RADIUS_LEN

#define MAX_RADIUS_LEN   4096

Definition at line 87 of file net.h.

◆ MIN_RADIUS_LEN

#define MIN_RADIUS_LEN   20

Definition at line 88 of file net.h.

◆ RADIUS_AUTH_VECTOR_LENGTH

#define RADIUS_AUTH_VECTOR_LENGTH   16

Definition at line 89 of file net.h.

◆ RADIUS_HEADER_LENGTH

#define RADIUS_HEADER_LENGTH   20

Definition at line 80 of file net.h.

Enumeration Type Documentation

◆ fr_dlt

enum fr_dlt
Enumerator
DLT_RAW 
DLT_NULL 
DLT_LOOP 
DLT_EN10MB 
DLT_LINUX_SLL 
DLT_PFLOG 

Definition at line 51 of file net.h.

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[]
extern

Strings for address families.

Definition at line 48 of file net.c.

◆ fr_net_af_table_len

size_t fr_net_af_table_len
extern

Definition at line 52 of file net.c.

◆ fr_net_ip_proto_table

fr_table_num_sorted_t const fr_net_ip_proto_table[]
extern

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
extern

Definition at line 34 of file net.c.

◆ fr_net_sock_type_table

fr_table_num_sorted_t const fr_net_sock_type_table[]
extern

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
extern

Definition at line 43 of file net.c.