FreeBSD kernel IPv4 code
ip_gre.c File Reference
#include <sys/cdefs.h>
#include "opt_inet.h"
#include "opt_inet6.h"
#include <sys/param.h>
#include <sys/jail.h>
#include <sys/systm.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/sockio.h>
#include <sys/mbuf.h>
#include <sys/errno.h>
#include <sys/kernel.h>
#include <sys/sysctl.h>
#include <sys/malloc.h>
#include <sys/proc.h>
#include <net/if.h>
#include <net/if_var.h>
#include <net/vnet.h>
#include <netinet/in.h>
#include <netinet/in_var.h>
#include <netinet/in_pcb.h>
#include <netinet/ip.h>
#include <netinet/ip_encap.h>
#include <netinet/ip_var.h>
#include <netinet/udp.h>
#include <netinet/udp_var.h>
#include <net/if_gre.h>
#include <machine/in_cksum.h>
Include dependency graph for ip_gre.c:

Go to the source code of this file.

Data Structures

struct  in_gre_socket
 

Macros

#define GRE_TTL   30
 
#define V_ip_gre_ttl   VNET(ip_gre_ttl)
 
#define V_ipv4_sockets   VNET(ipv4_sockets)
 
#define V_ipv4_hashtbl   VNET(ipv4_hashtbl)
 
#define V_ipv4_srchashtbl   VNET(ipv4_srchashtbl)
 
#define GRE_HASH(src, dst)
 
#define GRE_SRCHASH(src)
 
#define GRE_SOCKHASH(src)
 
#define GRE_HASH_SC(sc)
 

Functions

 __FBSDID ("$FreeBSD$")
 
 VNET_DEFINE (int, ip_gre_ttl)
 
 SYSCTL_INT (_net_inet_ip, OID_AUTO, grettl, CTLFLAG_VNET|CTLFLAG_RW, &VNET_NAME(ip_gre_ttl), 0, "Default TTL value for encapsulated packets")
 
 VNET_DEFINE_STATIC (struct gre_sockets *, ipv4_sockets)
 
 VNET_DEFINE_STATIC (struct gre_list *, ipv4_hashtbl)
 
 VNET_DEFINE_STATIC (struct gre_list *, ipv4_srchashtbl)
 
static uint32_t in_gre_hashval (in_addr_t src, in_addr_t dst)
 
static struct gre_socket * in_gre_lookup_socket (in_addr_t addr)
 
static int in_gre_checkdup (const struct gre_softc *sc, in_addr_t src, in_addr_t dst, uint32_t opts)
 
static int in_gre_lookup (const struct mbuf *m, int off, int proto, void **arg)
 
static void in_gre_set_running (struct gre_softc *sc)
 
static void in_gre_srcaddr (void *arg __unused, const struct sockaddr *sa, int event __unused)
 
static void in_gre_udp_input (struct mbuf *m, int off, struct inpcb *inp, const struct sockaddr *sa, void *ctx)
 
static int in_gre_setup_socket (struct gre_softc *sc)
 
static int in_gre_attach (struct gre_softc *sc)
 
int in_gre_setopts (struct gre_softc *sc, u_long cmd, uint32_t value)
 
int in_gre_ioctl (struct gre_softc *sc, u_long cmd, caddr_t data)
 
int in_gre_output (struct mbuf *m, int af, int hlen)
 
void in_gre_init (void)
 
void in_gre_uninit (void)
 

Variables

static const struct srcaddrtabipv4_srcaddrtab = NULL
 
static const struct encaptabecookie = NULL
 
static const struct encap_config ipv4_encap_cfg
 

Macro Definition Documentation

◆ GRE_HASH

#define GRE_HASH (   src,
  dst 
)
Value:
in_gre_hashval((src), (dst)) & (GRE_HASH_SIZE - 1)])
#define V_ipv4_hashtbl
Definition: ip_gre.c:90

Definition at line 92 of file ip_gre.c.

◆ GRE_HASH_SC

#define GRE_HASH_SC (   sc)
Value:
GRE_HASH((sc)->gre_oip.ip_src.s_addr,\
(sc)->gre_oip.ip_dst.s_addr)
#define GRE_HASH(src, dst)
Definition: ip_gre.c:92

Definition at line 98 of file ip_gre.c.

◆ GRE_SOCKHASH

#define GRE_SOCKHASH (   src)
Value:
fnv_32_buf(&(src), sizeof(src), FNV1_32_INIT) & (GRE_HASH_SIZE - 1)])
#define V_ipv4_sockets
Definition: ip_gre.c:89

Definition at line 96 of file ip_gre.c.

◆ GRE_SRCHASH

#define GRE_SRCHASH (   src)
Value:
fnv_32_buf(&(src), sizeof(src), FNV1_32_INIT) & (GRE_HASH_SIZE - 1)])
#define V_ipv4_srchashtbl
Definition: ip_gre.c:91

Definition at line 94 of file ip_gre.c.

◆ GRE_TTL

#define GRE_TTL   30

Definition at line 76 of file ip_gre.c.

◆ V_ip_gre_ttl

#define V_ip_gre_ttl   VNET(ip_gre_ttl)

Definition at line 78 of file ip_gre.c.

◆ V_ipv4_hashtbl

#define V_ipv4_hashtbl   VNET(ipv4_hashtbl)

Definition at line 90 of file ip_gre.c.

◆ V_ipv4_sockets

#define V_ipv4_sockets   VNET(ipv4_sockets)

Definition at line 89 of file ip_gre.c.

◆ V_ipv4_srchashtbl

#define V_ipv4_srchashtbl   VNET(ipv4_srchashtbl)

Definition at line 91 of file ip_gre.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ in_gre_attach()

static int in_gre_attach ( struct gre_softc *  sc)
static

Definition at line 348 of file ip_gre.c.

References GRE_HASH_SC, GRE_SRCHASH, in_gre_set_running(), in_gre_setup_socket(), in_pseudo(), IPPROTO_UDP, and IPVERSION.

Referenced by in_gre_ioctl(), and in_gre_setopts().

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

◆ in_gre_checkdup()

static int in_gre_checkdup ( const struct gre_softc *  sc,
in_addr_t  src,
in_addr_t  dst,
uint32_t  opts 
)
static

Definition at line 125 of file ip_gre.c.

References GRE_HASH, and in_gre_lookup_socket().

Referenced by in_gre_ioctl(), and in_gre_setopts().

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

◆ in_gre_hashval()

static uint32_t in_gre_hashval ( in_addr_t  src,
in_addr_t  dst 
)
static

Definition at line 102 of file ip_gre.c.

◆ in_gre_init()

void in_gre_init ( void  )

Definition at line 556 of file ip_gre.c.

References ecookie, in_gre_srcaddr(), ip_encap_attach(), ip_encap_register_srcaddr(), ipv4_encap_cfg, and ipv4_srcaddrtab.

Here is the call graph for this function:

◆ in_gre_ioctl()

int in_gre_ioctl ( struct gre_softc *  sc,
u_long  cmd,
caddr_t  data 
)

◆ in_gre_lookup()

static int in_gre_lookup ( const struct mbuf *  m,
int  off,
int  proto,
void **  arg 
)
static

Definition at line 157 of file ip_gre.c.

References ENCAP_DRV_LOOKUP, GRE_HASH, ip::ip_dst, in_addr::s_addr, and V_ipv4_hashtbl.

◆ in_gre_lookup_socket()

static struct gre_socket * in_gre_lookup_socket ( in_addr_t  addr)
static

Definition at line 111 of file ip_gre.c.

References in_gre_socket::addr, in_gre_socket::base, and GRE_SOCKHASH.

Referenced by in_gre_checkdup(), and in_gre_setup_socket().

Here is the caller graph for this function:

◆ in_gre_output()

int in_gre_output ( struct mbuf *  m,
int  af,
int  hlen 
)

Definition at line 516 of file ip_gre.c.

References ip_fillid(), IP_FORWARDING, ip_id, ip_output(), ip_tos, and V_ip_gre_ttl.

Here is the call graph for this function:

◆ in_gre_set_running()

static void in_gre_set_running ( struct gre_softc *  sc)
static

Definition at line 188 of file ip_gre.c.

References in_localip().

Referenced by in_gre_attach(), and in_gre_srcaddr().

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

◆ in_gre_setopts()

int in_gre_setopts ( struct gre_softc *  sc,
u_long  cmd,
uint32_t  value 
)

Definition at line 392 of file ip_gre.c.

References in_gre_attach(), and in_gre_checkdup().

Here is the call graph for this function:

◆ in_gre_setup_socket()

static int in_gre_setup_socket ( struct gre_softc *  sc)
static

◆ in_gre_srcaddr()

static void in_gre_srcaddr ( void *arg  __unused,
const struct sockaddr *  sa,
int event  __unused 
)
static

Definition at line 203 of file ip_gre.c.

References GRE_SRCHASH, in_gre_set_running(), in_addr::s_addr, sockaddr_in::sin_addr, and V_ipv4_hashtbl.

Referenced by in_gre_init().

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

◆ in_gre_udp_input()

static void in_gre_udp_input ( struct mbuf *  m,
int  off,
struct inpcb inp,
const struct sockaddr *  sa,
void *  ctx 
)
static

Definition at line 223 of file ip_gre.c.

References IPPROTO_UDP.

Referenced by in_gre_setup_socket().

Here is the caller graph for this function:

◆ in_gre_uninit()

void in_gre_uninit ( void  )

Definition at line 567 of file ip_gre.c.

References ecookie, ip_encap_detach(), ip_encap_unregister_srcaddr(), ipv4_srcaddrtab, V_ipv4_hashtbl, V_ipv4_sockets, and V_ipv4_srchashtbl.

Here is the call graph for this function:

◆ SYSCTL_INT()

SYSCTL_INT ( _net_inet_ip  ,
OID_AUTO  ,
grettl  ,
CTLFLAG_VNET|  CTLFLAG_RW,
VNET_NAMEip_gre_ttl,
,
"Default TTL value for encapsulated packets"   
)

◆ VNET_DEFINE()

VNET_DEFINE ( int  ,
ip_gre_ttl   
)

◆ VNET_DEFINE_STATIC() [1/3]

VNET_DEFINE_STATIC ( struct gre_list *  ,
ipv4_hashtbl   
)

◆ VNET_DEFINE_STATIC() [2/3]

VNET_DEFINE_STATIC ( struct gre_list *  ,
ipv4_srchashtbl   
)

◆ VNET_DEFINE_STATIC() [3/3]

VNET_DEFINE_STATIC ( struct gre_sockets *  ,
ipv4_sockets   
)

Variable Documentation

◆ ecookie

const struct encaptab* ecookie = NULL
static

Definition at line 546 of file ip_gre.c.

Referenced by in_gre_init(), and in_gre_uninit().

◆ ipv4_encap_cfg

const struct encap_config ipv4_encap_cfg
static
Initial value:
= {
.proto = IPPROTO_GRE,
.min_length = sizeof(struct greip) + sizeof(struct ip),
.exact_match = ENCAP_DRV_LOOKUP,
.lookup = in_gre_lookup,
.input = gre_input
}
#define ENCAP_DRV_LOOKUP
Definition: ip_encap.h:54
static int in_gre_lookup(const struct mbuf *m, int off, int proto, void **arg)
Definition: ip_gre.c:157
Definition: ip.h:51

Definition at line 547 of file ip_gre.c.

Referenced by in_gre_init().

◆ ipv4_srcaddrtab

const struct srcaddrtab* ipv4_srcaddrtab = NULL
static

Definition at line 545 of file ip_gre.c.

Referenced by in_gre_init(), and in_gre_uninit().