FreeBSD kernel IPv4 code
ip_id.c File Reference
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/counter.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/random.h>
#include <sys/smp.h>
#include <sys/sysctl.h>
#include <sys/bitstring.h>
#include <net/vnet.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/ip_var.h>
Include dependency graph for ip_id.c:

Go to the source code of this file.

Macros

#define V_ip_rfc6864   VNET(ip_rfc6864)
 
#define V_ip_do_randomid   VNET(ip_do_randomid)
 
#define V_id_array   VNET(id_array)
 
#define V_id_bits   VNET(id_bits)
 
#define V_array_ptr   VNET(array_ptr)
 
#define V_array_size   VNET(array_size)
 
#define V_random_id_collisions   VNET(random_id_collisions)
 
#define V_random_id_total   VNET(random_id_total)
 
#define V_ip_id_mtx   VNET(ip_id_mtx)
 
#define V_ip_id   VNET(ip_id)
 

Functions

 __FBSDID ("$FreeBSD$")
 
 VNET_DEFINE_STATIC (int, ip_rfc6864)
 
 VNET_DEFINE_STATIC (int, ip_do_randomid)=0
 
static MALLOC_DEFINE (M_IPID, "ipid", "randomized ip id state")
 
 VNET_DEFINE_STATIC (uint16_t *, id_array)
 
 VNET_DEFINE_STATIC (bitstr_t *, id_bits)
 
 VNET_DEFINE_STATIC (int, array_ptr)
 
 VNET_DEFINE_STATIC (int, array_size)
 
 VNET_DEFINE_STATIC (int, random_id_collisions)
 
 VNET_DEFINE_STATIC (int, random_id_total)
 
 VNET_DEFINE_STATIC (struct mtx, ip_id_mtx)
 
 VNET_DEFINE_STATIC (counter_u64_t, ip_id)
 
static int sysctl_ip_randomid (SYSCTL_HANDLER_ARGS)
 
static int sysctl_ip_id_change (SYSCTL_HANDLER_ARGS)
 
static void ip_initid (int)
 
static uint16_t ip_randomid (void)
 
static void ipid_sysinit (void)
 
static void ipid_sysuninit (void)
 
 SYSCTL_DECL (_net_inet_ip)
 
 SYSCTL_PROC (_net_inet_ip, OID_AUTO, random_id, CTLTYPE_INT|CTLFLAG_VNET|CTLFLAG_RW|CTLFLAG_MPSAFE, &VNET_NAME(ip_do_randomid), 0, sysctl_ip_randomid, "IU", "Assign random ip_id values")
 
 SYSCTL_INT (_net_inet_ip, OID_AUTO, rfc6864, CTLFLAG_VNET|CTLFLAG_RW, &VNET_NAME(ip_rfc6864), 0, "Use constant IP ID for atomic datagrams")
 
 SYSCTL_PROC (_net_inet_ip, OID_AUTO, random_id_period, CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_VNET|CTLFLAG_MPSAFE, &VNET_NAME(array_size), 0, sysctl_ip_id_change, "IU", "IP ID Array size")
 
 SYSCTL_INT (_net_inet_ip, OID_AUTO, random_id_collisions, CTLFLAG_RD|CTLFLAG_VNET, &VNET_NAME(random_id_collisions), 0, "Count of IP ID collisions")
 
 SYSCTL_INT (_net_inet_ip, OID_AUTO, random_id_total, CTLFLAG_RD|CTLFLAG_VNET, &VNET_NAME(random_id_total), 0, "Count of IP IDs created")
 
void ip_fillid (struct ip *ip)
 
 VNET_SYSINIT (ip_id, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY, ipid_sysinit, NULL)
 
 VNET_SYSUNINIT (ip_id, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, ipid_sysuninit, NULL)
 

Macro Definition Documentation

◆ V_array_ptr

#define V_array_ptr   VNET(array_ptr)

Definition at line 119 of file ip_id.c.

◆ V_array_size

#define V_array_size   VNET(array_size)

Definition at line 120 of file ip_id.c.

◆ V_id_array

#define V_id_array   VNET(id_array)

Definition at line 117 of file ip_id.c.

◆ V_id_bits

#define V_id_bits   VNET(id_bits)

Definition at line 118 of file ip_id.c.

◆ V_ip_do_randomid

#define V_ip_do_randomid   VNET(ip_do_randomid)

Definition at line 104 of file ip_id.c.

◆ V_ip_id

#define V_ip_id   VNET(ip_id)

Definition at line 129 of file ip_id.c.

◆ V_ip_id_mtx

#define V_ip_id_mtx   VNET(ip_id_mtx)

Definition at line 123 of file ip_id.c.

◆ V_ip_rfc6864

#define V_ip_rfc6864   VNET(ip_rfc6864)

Definition at line 103 of file ip_id.c.

◆ V_random_id_collisions

#define V_random_id_collisions   VNET(random_id_collisions)

Definition at line 121 of file ip_id.c.

◆ V_random_id_total

#define V_random_id_total   VNET(random_id_total)

Definition at line 122 of file ip_id.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ ip_fillid()

void ip_fillid ( struct ip ip)

Definition at line 243 of file ip_id.c.

References IP_DF, ip::ip_id, ip::ip_off, ip_randomid(), V_ip_do_randomid, V_ip_id, and V_ip_rfc6864.

Referenced by carp_send_ad_locked(), in_gre_output(), ip_output(), pim_register_send_rp(), sctp_lowlevel_chunk_output(), and sctp_send_resp_msg().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ip_initid()

static void ip_initid ( int  new_size)
static

Definition at line 192 of file ip_id.c.

References V_array_ptr, V_array_size, V_id_array, V_id_bits, V_ip_id_mtx, V_random_id_collisions, and V_random_id_total.

Referenced by sysctl_ip_id_change(), and sysctl_ip_randomid().

Here is the caller graph for this function:

◆ ip_randomid()

static uint16_t ip_randomid ( void  )
static

Definition at line 216 of file ip_id.c.

References V_array_ptr, V_array_size, V_id_array, V_id_bits, V_ip_id_mtx, V_random_id_collisions, and V_random_id_total.

Referenced by ip_fillid().

Here is the caller graph for this function:

◆ ipid_sysinit()

static void ipid_sysinit ( void  )
static

Definition at line 277 of file ip_id.c.

References V_ip_id, and V_ip_id_mtx.

◆ ipid_sysuninit()

static void ipid_sysuninit ( void  )
static

Definition at line 290 of file ip_id.c.

References V_id_array, V_id_bits, V_ip_id, and V_ip_id_mtx.

◆ MALLOC_DEFINE()

static MALLOC_DEFINE ( M_IPID  ,
"ipid"  ,
"randomized ip id state  
)
static

◆ SYSCTL_DECL()

SYSCTL_DECL ( _net_inet_ip  )

◆ SYSCTL_INT() [1/3]

SYSCTL_INT ( _net_inet_ip  ,
OID_AUTO  ,
random_id_collisions  ,
CTLFLAG_RD|  CTLFLAG_VNET,
VNET_NAMErandom_id_collisions,
,
"Count of IP ID collisions"   
)

◆ SYSCTL_INT() [2/3]

SYSCTL_INT ( _net_inet_ip  ,
OID_AUTO  ,
random_id_total  ,
CTLFLAG_RD|  CTLFLAG_VNET,
VNET_NAMErandom_id_total,
,
"Count of IP IDs created"   
)

◆ SYSCTL_INT() [3/3]

SYSCTL_INT ( _net_inet_ip  ,
OID_AUTO  ,
rfc6864  ,
CTLFLAG_VNET|  CTLFLAG_RW,
VNET_NAMEip_rfc6864,
,
"Use constant IP ID for atomic datagrams"   
)

◆ sysctl_ip_id_change()

static int sysctl_ip_id_change ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 176 of file ip_id.c.

References ip_initid(), and V_array_size.

Here is the call graph for this function:

◆ sysctl_ip_randomid()

static int sysctl_ip_randomid ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 156 of file ip_id.c.

References ip_initid(), and V_ip_do_randomid.

Here is the call graph for this function:

◆ SYSCTL_PROC() [1/2]

SYSCTL_PROC ( _net_inet_ip  ,
OID_AUTO  ,
random_id  ,
CTLTYPE_INT|CTLFLAG_VNET|CTLFLAG_RW|  CTLFLAG_MPSAFE,
VNET_NAMEip_do_randomid,
,
sysctl_ip_randomid  ,
"IU"  ,
"Assign random ip_id values"   
)

◆ SYSCTL_PROC() [2/2]

SYSCTL_PROC ( _net_inet_ip  ,
OID_AUTO  ,
random_id_period  ,
CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_VNET|  CTLFLAG_MPSAFE,
VNET_NAMEarray_size,
,
sysctl_ip_id_change  ,
"IU"  ,
"IP ID Array size"   
)

◆ VNET_DEFINE_STATIC() [1/10]

VNET_DEFINE_STATIC ( bitstr_t *  ,
id_bits   
)

◆ VNET_DEFINE_STATIC() [2/10]

VNET_DEFINE_STATIC ( counter_u64_t  ,
ip_id   
)

◆ VNET_DEFINE_STATIC() [3/10]

VNET_DEFINE_STATIC ( int  ,
array_ptr   
)

◆ VNET_DEFINE_STATIC() [4/10]

VNET_DEFINE_STATIC ( int  ,
array_size   
)

◆ VNET_DEFINE_STATIC() [5/10]

VNET_DEFINE_STATIC ( int  ,
ip_do_randomid   
)
pure virtual

◆ VNET_DEFINE_STATIC() [6/10]

VNET_DEFINE_STATIC ( int  ,
ip_rfc6864   
)

◆ VNET_DEFINE_STATIC() [7/10]

VNET_DEFINE_STATIC ( int  ,
random_id_collisions   
)

◆ VNET_DEFINE_STATIC() [8/10]

VNET_DEFINE_STATIC ( int  ,
random_id_total   
)

◆ VNET_DEFINE_STATIC() [9/10]

VNET_DEFINE_STATIC ( struct mtx  ,
ip_id_mtx   
)

◆ VNET_DEFINE_STATIC() [10/10]

VNET_DEFINE_STATIC ( uint16_t ,
id_array   
)

◆ VNET_SYSINIT()

VNET_SYSINIT ( ip_id  ,
SI_SUB_PROTO_DOMAIN  ,
SI_ORDER_ANY  ,
ipid_sysinit  ,
NULL   
)

◆ VNET_SYSUNINIT()

VNET_SYSUNINIT ( ip_id  ,
SI_SUB_PROTO_DOMAIN  ,
SI_ORDER_THIRD  ,
ipid_sysuninit  ,
NULL   
)