FreeBSD kernel IPv4 code
ip_input.c File Reference
#include <sys/cdefs.h>
#include "opt_bootp.h"
#include "opt_ipstealth.h"
#include "opt_ipsec.h"
#include "opt_route.h"
#include "opt_rss.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/hhook.h>
#include <sys/mbuf.h>
#include <sys/malloc.h>
#include <sys/domain.h>
#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/rmlock.h>
#include <sys/rwlock.h>
#include <sys/sdt.h>
#include <sys/syslog.h>
#include <sys/sysctl.h>
#include <net/if.h>
#include <net/if_types.h>
#include <net/if_var.h>
#include <net/if_dl.h>
#include <net/pfil.h>
#include <net/route.h>
#include <net/route/nhop.h>
#include <net/netisr.h>
#include <net/rss_config.h>
#include <net/vnet.h>
#include <netinet/in.h>
#include <netinet/in_kdtrace.h>
#include <netinet/in_systm.h>
#include <netinet/in_var.h>
#include <netinet/ip.h>
#include <netinet/in_fib.h>
#include <netinet/in_pcb.h>
#include <netinet/ip_var.h>
#include <netinet/ip_fw.h>
#include <netinet/ip_icmp.h>
#include <netinet/ip_options.h>
#include <machine/in_cksum.h>
#include <netinet/ip_carp.h>
#include <netinet/in_rss.h>
#include <netipsec/ipsec_support.h>
#include <sys/socketvar.h>
#include <security/mac/mac_framework.h>
Include dependency graph for ip_input.c:

Go to the source code of this file.

Macros

#define V_ip_strong_es   VNET(ip_strong_es)
 
#define V_ip_sav   VNET(ip_sav)
 
#define CHECK_SO_CT(sp, ct)    (((sp->so_options & SO_TIMESTAMP) && (sp->so_ts_clock == ct)) ? 1 : 0)
 
#define V_ip_rsvp_on   VNET(ip_rsvp_on)
 

Functions

 __FBSDID ("$FreeBSD$")
 
void ipreass_init (void)
 
void ipreass_drain (void)
 
void ipreass_slowtimo (void)
 
 VNET_DEFINE (int, rsvp_on)
 
 VNET_DEFINE (int, ipforwarding)
 
 SYSCTL_INT (_net_inet_ip, IPCTL_FORWARDING, forwarding, CTLFLAG_VNET|CTLFLAG_RW, &VNET_NAME(ipforwarding), 0, "Enable IP forwarding between interfaces")
 
 VNET_DEFINE (int, ipsendredirects)
 
 SYSCTL_INT (_net_inet_ip, IPCTL_SENDREDIRECTS, redirect, CTLFLAG_VNET|CTLFLAG_RW, &VNET_NAME(ipsendredirects), 0, "Enable sending IP redirects")
 
 VNET_DEFINE_STATIC (bool, ip_strong_es)
 
 SYSCTL_BOOL (_net_inet_ip, OID_AUTO, rfc1122_strong_es, CTLFLAG_VNET|CTLFLAG_RW, &VNET_NAME(ip_strong_es), false, "Packet's IP destination address must match address on arrival interface")
 
 VNET_DEFINE_STATIC (bool, ip_sav)
 
 SYSCTL_BOOL (_net_inet_ip, OID_AUTO, source_address_validation, CTLFLAG_VNET|CTLFLAG_RW, &VNET_NAME(ip_sav), true, "Drop incoming packets with source address that is a local address")
 
 VNET_DEFINE (pfil_head_t, inet_pfil_head)
 
 VNET_DEFINE (struct in_ifaddrhead, in_ifaddrhead)
 
 VNET_DEFINE (struct in_ifaddrhashhead *, in_ifaddrhashtbl)
 
 VNET_DEFINE (u_long, in_ifaddrhmask)
 
 CTASSERT (sizeof(struct in_ifaddrhashhead)==sizeof(LIST_HEAD(, in_addr)))
 
 VNET_PCPUSTAT_DEFINE (struct ipstat, ipstat)
 
 VNET_PCPUSTAT_SYSINIT (ipstat)
 
 SYSCTL_VNET_PCPUSTAT (_net_inet_ip, IPCTL_STATS, stats, struct ipstat, ipstat, "IP statistics (struct ipstat, netinet/ip_var.h)")
 
void kmod_ipstat_inc (int statnum)
 
void kmod_ipstat_dec (int statnum)
 
static int sysctl_netinet_intr_queue_maxlen (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_net_inet_ip, IPCTL_INTRQMAXLEN, intr_queue_maxlen, CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_MPSAFE, 0, 0, sysctl_netinet_intr_queue_maxlen, "I", "Maximum size of the IP input queue")
 
static int sysctl_netinet_intr_queue_drops (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_net_inet_ip, IPCTL_INTRQDROPS, intr_queue_drops, CTLTYPE_INT|CTLFLAG_RD|CTLFLAG_MPSAFE, 0, 0, sysctl_netinet_intr_queue_drops, "I", "Number of packets dropped from the IP input queue")
 
static void ip_vnet_init (void *arg __unused)
 
 VNET_SYSINIT (ip_vnet_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH, ip_vnet_init, NULL)
 
static void ip_init (const void *unused __unused)
 
 SYSINIT (ip_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, ip_init, NULL)
 
void ip_input (struct mbuf *m)
 
void ip_slowtimo (void)
 
void ip_drain (void)
 
int ipproto_register (short ipproto)
 
int ipproto_unregister (short ipproto)
 
void ip_forward (struct mbuf *m, int srcrt)
 
void ip_savecontrol (struct inpcb *inp, struct mbuf **mp, struct ip *ip, struct mbuf *m)
 
 VNET_DEFINE_STATIC (int, ip_rsvp_on)
 
 VNET_DEFINE (struct socket *, ip_rsvpd)
 
int ip_rsvp_init (struct socket *so)
 
int ip_rsvp_done (void)
 
int rsvp_input (struct mbuf **mp, int *offp, int proto)
 

Variables

static struct netisr_handler ip_nh
 
struct domain inetdomain
 
struct protosw inetsw []
 
u_char ip_protox [IPPROTO_MAX]
 
u_char inetctlerrmap [PRC_NCMDS]
 

Macro Definition Documentation

◆ CHECK_SO_CT

#define CHECK_SO_CT (   sp,
  ct 
)     (((sp->so_options & SO_TIMESTAMP) && (sp->so_ts_clock == ct)) ? 1 : 0)

Definition at line 1146 of file ip_input.c.

◆ V_ip_rsvp_on

#define V_ip_rsvp_on   VNET(ip_rsvp_on)

Definition at line 1363 of file ip_input.c.

◆ V_ip_sav

#define V_ip_sav   VNET(ip_sav)

Definition at line 127 of file ip_input.c.

◆ V_ip_strong_es

#define V_ip_strong_es   VNET(ip_strong_es)

Definition at line 121 of file ip_input.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ CTASSERT()

CTASSERT ( sizeof(struct in_ifaddrhashhead)  = =sizeof(LIST_HEAD(, in_addr)))

◆ ip_drain()

void ip_drain ( void  )

Definition at line 866 of file ip_input.c.

References ipreass_drain().

Here is the call graph for this function:

◆ ip_forward()

◆ ip_init()

static void ip_init ( const void *unused  __unused)
static

Definition at line 344 of file ip_input.c.

References inetdomain, inetsw, ip_nh, and ip_protox.

◆ ip_input()

◆ ip_rsvp_done()

int ip_rsvp_done ( void  )

Definition at line 1390 of file ip_input.c.

References V_ip_rsvp_on, V_ip_rsvpd, and V_rsvp_on.

◆ ip_rsvp_init()

int ip_rsvp_init ( struct socket *  so)

Definition at line 1366 of file ip_input.c.

References V_ip_rsvp_on, V_ip_rsvpd, and V_rsvp_on.

◆ ip_savecontrol()

void ip_savecontrol ( struct inpcb inp,
struct mbuf **  mp,
struct ip ip,
struct mbuf *  m 
)

◆ ip_slowtimo()

void ip_slowtimo ( void  )

Definition at line 852 of file ip_input.c.

References ipreass_slowtimo().

Here is the call graph for this function:

◆ ip_vnet_init()

static void ip_vnet_init ( void *arg  __unused)
static

Definition at line 304 of file ip_input.c.

References INADDR_NHASH, ip_nh, ipreass_init(), PFIL_INET_NAME, V_in_ifaddrhashtbl, V_in_ifaddrhead, V_in_ifaddrhmask, and V_inet_pfil_head.

Here is the call graph for this function:

◆ ipproto_register()

int ipproto_register ( short  ipproto)

Definition at line 884 of file ip_input.c.

References inetdomain, inetsw, and ip_protox.

Referenced by carp_mod_load(), and sctp_module_load().

Here is the caller graph for this function:

◆ ipproto_unregister()

int ipproto_unregister ( short  ipproto)

Definition at line 915 of file ip_input.c.

References inetsw, and ip_protox.

Referenced by carp_mod_cleanup(), and sctp_module_unload().

Here is the caller graph for this function:

◆ ipreass_drain()

void ipreass_drain ( void  )

Definition at line 614 of file ip_reass.c.

References count, ipq_drop(), IPQ_LOCK, IPQ_UNLOCK, IPREASS_NHASH, and V_ipq.

Referenced by ip_drain(), and sysctl_maxfragpackets().

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

◆ ipreass_init()

void ipreass_init ( void  )

Definition at line 563 of file ip_reass.c.

References IP_MAXFRAGPACKETS, IP_MAXFRAGS, IPREASS_NHASH, ipreass_zone_change(), maxfrags, V_ipq, V_ipq_hashseed, V_ipq_zone, V_ipreass_maxbucketsize, and V_maxfragsperpacket.

Referenced by ip_vnet_init().

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

◆ ipreass_slowtimo()

void ipreass_slowtimo ( void  )

Definition at line 592 of file ip_reass.c.

References IPQ_LOCK, ipq_timeout(), ipq::ipq_ttl, IPQ_UNLOCK, IPREASS_NHASH, nfrags, and V_ipq.

Referenced by ip_slowtimo().

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

◆ kmod_ipstat_dec()

void kmod_ipstat_dec ( int  statnum)

Definition at line 211 of file ip_input.c.

◆ kmod_ipstat_inc()

void kmod_ipstat_inc ( int  statnum)

Definition at line 204 of file ip_input.c.

◆ rsvp_input()

int rsvp_input ( struct mbuf **  mp,
int *  offp,
int  proto 
)

Definition at line 1406 of file ip_input.c.

References rip_input(), rsvp_input_p, V_ip_rsvpd, and V_rsvp_on.

Here is the call graph for this function:

◆ SYSCTL_BOOL() [1/2]

SYSCTL_BOOL ( _net_inet_ip  ,
OID_AUTO  ,
rfc1122_strong_es  ,
CTLFLAG_VNET|  CTLFLAG_RW,
VNET_NAMEip_strong_es,
false  ,
"Packet's IP destination address must match address on arrival interface"   
)

◆ SYSCTL_BOOL() [2/2]

SYSCTL_BOOL ( _net_inet_ip  ,
OID_AUTO  ,
source_address_validation  ,
CTLFLAG_VNET|  CTLFLAG_RW,
VNET_NAMEip_sav,
true  ,
"Drop incoming packets with source address that is a local address"   
)

◆ SYSCTL_INT() [1/2]

SYSCTL_INT ( _net_inet_ip  ,
IPCTL_FORWARDING  ,
forwarding  ,
CTLFLAG_VNET|  CTLFLAG_RW,
VNET_NAMEipforwarding,
,
"Enable IP forwarding between interfaces"   
)

◆ SYSCTL_INT() [2/2]

SYSCTL_INT ( _net_inet_ip  ,
IPCTL_SENDREDIRECTS  ,
redirect  ,
CTLFLAG_VNET|  CTLFLAG_RW,
VNET_NAMEipsendredirects,
,
"Enable sending IP redirects"   
)

◆ sysctl_netinet_intr_queue_drops()

static int sysctl_netinet_intr_queue_drops ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 236 of file ip_input.c.

References ip_nh.

◆ sysctl_netinet_intr_queue_maxlen()

static int sysctl_netinet_intr_queue_maxlen ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 218 of file ip_input.c.

References ip_nh.

◆ SYSCTL_PROC() [1/2]

SYSCTL_PROC ( _net_inet_ip  ,
IPCTL_INTRQDROPS  ,
intr_queue_drops  ,
CTLTYPE_INT|CTLFLAG_RD|  CTLFLAG_MPSAFE,
,
,
sysctl_netinet_intr_queue_drops  ,
"I"  ,
"Number of packets dropped from the IP input queue"   
)

◆ SYSCTL_PROC() [2/2]

SYSCTL_PROC ( _net_inet_ip  ,
IPCTL_INTRQMAXLEN  ,
intr_queue_maxlen  ,
CTLTYPE_INT|CTLFLAG_RW|  CTLFLAG_MPSAFE,
,
,
sysctl_netinet_intr_queue_maxlen  ,
"I"  ,
"Maximum size of the IP input queue"   
)

◆ SYSCTL_VNET_PCPUSTAT()

SYSCTL_VNET_PCPUSTAT ( _net_inet_ip  ,
IPCTL_STATS  ,
stats  ,
struct ipstat  ,
ipstat  ,
"IP statistics (struct ipstat, netinet/ip_var.h)"   
)

◆ SYSINIT()

SYSINIT ( ip_init  ,
SI_SUB_PROTO_DOMAIN  ,
SI_ORDER_THIRD  ,
ip_init  ,
NULL   
)

◆ VNET_DEFINE() [1/8]

VNET_DEFINE ( int  ,
ipforwarding   
)

◆ VNET_DEFINE() [2/8]

VNET_DEFINE ( int  ,
ipsendredirects   
)

◆ VNET_DEFINE() [3/8]

VNET_DEFINE ( int  ,
rsvp_on   
)

◆ VNET_DEFINE() [4/8]

VNET_DEFINE ( pfil_head_t  ,
inet_pfil_head   
)

◆ VNET_DEFINE() [5/8]

VNET_DEFINE ( struct in_ifaddrhashhead *  ,
in_ifaddrhashtbl   
)

◆ VNET_DEFINE() [6/8]

VNET_DEFINE ( struct in_ifaddrhead  ,
in_ifaddrhead   
)

◆ VNET_DEFINE() [7/8]

VNET_DEFINE ( struct socket *  ,
ip_rsvpd   
)

◆ VNET_DEFINE() [8/8]

VNET_DEFINE ( u_long  ,
in_ifaddrhmask   
)

◆ VNET_DEFINE_STATIC() [1/3]

VNET_DEFINE_STATIC ( bool  ,
ip_sav   
)

◆ VNET_DEFINE_STATIC() [2/3]

VNET_DEFINE_STATIC ( bool  ,
ip_strong_es   
)

◆ VNET_DEFINE_STATIC() [3/3]

VNET_DEFINE_STATIC ( int  ,
ip_rsvp_on   
)

◆ VNET_PCPUSTAT_DEFINE()

VNET_PCPUSTAT_DEFINE ( struct ipstat  ,
ipstat   
)

◆ VNET_PCPUSTAT_SYSINIT()

VNET_PCPUSTAT_SYSINIT ( ipstat  )

◆ VNET_SYSINIT()

VNET_SYSINIT ( ip_vnet_init  ,
SI_SUB_PROTO_DOMAIN  ,
SI_ORDER_FOURTH  ,
ip_vnet_init  ,
NULL   
)

Variable Documentation

◆ inetctlerrmap

u_char inetctlerrmap[PRC_NCMDS]
Initial value:
= {
0, 0, 0, 0,
0, EMSGSIZE, EHOSTDOWN, EHOSTUNREACH,
EHOSTUNREACH, EHOSTUNREACH, ECONNREFUSED, ECONNREFUSED,
EMSGSIZE, EHOSTUNREACH, 0, 0,
0, 0, EHOSTUNREACH, 0,
ENOPROTOOPT, ECONNREFUSED
}

Definition at line 935 of file ip_input.c.

◆ inetdomain

struct domain inetdomain
extern

Referenced by ip_init(), and ipproto_register().

◆ inetsw

struct protosw inetsw[]
extern

◆ ip_nh

struct netisr_handler ip_nh
static
Initial value:
= {
.nh_name = "ip",
.nh_handler = ip_input,
.nh_proto = NETISR_IP,
.nh_policy = NETISR_POLICY_FLOW,
}
void ip_input(struct mbuf *m)
Definition: ip_input.c:448

Definition at line 134 of file ip_input.c.

Referenced by ip_init(), ip_vnet_init(), sysctl_netinet_intr_queue_drops(), and sysctl_netinet_intr_queue_maxlen().

◆ ip_protox

u_char ip_protox[IPPROTO_MAX]

Definition at line 167 of file ip_input.c.

Referenced by ip_init(), ip_input(), ipproto_register(), and ipproto_unregister().