2005-01-07 01:45:51 +00:00
|
|
|
/*-
|
2017-11-20 19:43:44 +00:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
1994-05-24 10:09:53 +00:00
|
|
|
* Copyright (c) 1982, 1986, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2017-02-28 23:42:47 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-05-24 10:09:53 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1995-09-21 18:04:43 +00:00
|
|
|
* @(#)ip_var.h 8.2 (Berkeley) 1/9/95
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
|
|
|
|
1994-08-21 05:27:42 +00:00
|
|
|
#ifndef _NETINET_IP_VAR_H_
|
1996-10-15 16:54:47 +00:00
|
|
|
#define _NETINET_IP_VAR_H_
|
1994-08-21 05:27:42 +00:00
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
#include <sys/queue.h>
|
2018-05-20 00:22:28 +00:00
|
|
|
#include <sys/epoch.h>
|
2001-06-11 12:39:29 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Overlay for ip header used by other protocols (tcp, udp).
|
|
|
|
*/
|
|
|
|
struct ipovly {
|
1998-08-24 07:47:39 +00:00
|
|
|
u_char ih_x1[9]; /* (unused) */
|
1994-05-24 10:09:53 +00:00
|
|
|
u_char ih_pr; /* protocol */
|
1996-10-25 17:57:53 +00:00
|
|
|
u_short ih_len; /* protocol length */
|
1994-05-24 10:09:53 +00:00
|
|
|
struct in_addr ih_src; /* source internet address */
|
|
|
|
struct in_addr ih_dst; /* destination internet address */
|
|
|
|
};
|
|
|
|
|
2002-07-20 22:46:20 +00:00
|
|
|
#ifdef _KERNEL
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Ip reassembly queue structure. Each fragment
|
|
|
|
* being reassembled is attached to one of these structures.
|
|
|
|
* They are timed out after ipq_ttl drops to 0, and may also
|
|
|
|
* be reclaimed if memory becomes tight.
|
|
|
|
*/
|
|
|
|
struct ipq {
|
2001-03-16 20:00:53 +00:00
|
|
|
TAILQ_ENTRY(ipq) ipq_list; /* to other reass headers */
|
1994-05-24 10:09:53 +00:00
|
|
|
u_char ipq_ttl; /* time for reass q to live */
|
|
|
|
u_char ipq_p; /* protocol of this fragment */
|
|
|
|
u_short ipq_id; /* sequence id for reassembly */
|
2018-11-16 18:32:48 +00:00
|
|
|
int ipq_maxoff; /* total length of packet */
|
1998-08-24 07:47:39 +00:00
|
|
|
struct mbuf *ipq_frags; /* to ip headers of fragments */
|
1994-05-24 10:09:53 +00:00
|
|
|
struct in_addr ipq_src,ipq_dst;
|
2003-02-22 06:41:47 +00:00
|
|
|
u_char ipq_nfrags; /* # frags in this packet */
|
2007-04-04 15:30:31 +00:00
|
|
|
struct label *ipq_label; /* MAC label */
|
1994-05-24 10:09:53 +00:00
|
|
|
};
|
2002-07-20 22:46:20 +00:00
|
|
|
#endif /* _KERNEL */
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2005-11-19 14:01:32 +00:00
|
|
|
/*
|
|
|
|
* Structure stored in mbuf in inpcb.ip_options
|
|
|
|
* and passed to ip_output when ip options are in use.
|
|
|
|
* The actual length of the options (including ipopt_dst)
|
|
|
|
* is in m_len.
|
|
|
|
*/
|
|
|
|
#define MAX_IPOPTLEN 40
|
|
|
|
|
|
|
|
struct ipoption {
|
|
|
|
struct in_addr ipopt_dst; /* first-hop dst if source routed */
|
|
|
|
char ipopt_list[MAX_IPOPTLEN]; /* options proper */
|
|
|
|
};
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Structure attached to inpcb.ip_moptions and
|
|
|
|
* passed to ip_output when IP multicast options are in use.
|
Import rewrite of IPv4 socket multicast layer to support source-specific
and protocol-independent host mode multicast. The code is written to
accomodate IPv6, IGMPv3 and MLDv2 with only a little additional work.
This change only pertains to FreeBSD's use as a multicast end-station and
does not concern multicast routing; for an IGMPv3/MLDv2 router
implementation, consider the XORP project.
The work is based on Wilbert de Graaf's IGMPv3 code drop for FreeBSD 4.6,
which is available at: http://www.kloosterhof.com/wilbert/igmpv3.html
Summary
* IPv4 multicast socket processing is now moved out of ip_output.c
into a new module, in_mcast.c.
* The in_mcast.c module implements the IPv4 legacy any-source API in
terms of the protocol-independent source-specific API.
* Source filters are lazy allocated as the common case does not use them.
They are part of per inpcb state and are covered by the inpcb lock.
* struct ip_mreqn is now supported to allow applications to specify
multicast joins by interface index in the legacy IPv4 any-source API.
* In UDP, an incoming multicast datagram only requires that the source
port matches the 4-tuple if the socket was already bound by source port.
An unbound socket SHOULD be able to receive multicasts sent from an
ephemeral source port.
* The UDP socket multicast filter mode defaults to exclusive, that is,
sources present in the per-socket list will be blocked from delivery.
* The RFC 3678 userland functions have been added to libc: setsourcefilter,
getsourcefilter, setipv4sourcefilter, getipv4sourcefilter.
* Definitions for IGMPv3 are merged but not yet used.
* struct sockaddr_storage is now referenced from <netinet/in.h>. It
is therefore defined there if not already declared in the same way
as for the C99 types.
* The RFC 1724 hack (specify 0.0.0.0/8 addresses to IP_MULTICAST_IF
which are then interpreted as interface indexes) is now deprecated.
* A patch for the Rhyolite.com routed in the FreeBSD base system
is available in the -net archives. This only affects individuals
running RIPv1 or RIPv2 via point-to-point and/or unnumbered interfaces.
* Make IPv6 detach path similar to IPv4's in code flow; functionally same.
* Bump __FreeBSD_version to 700048; see UPDATING.
This work was financially supported by another FreeBSD committer.
Obtained from: p4://bms_netdev
Submitted by: Wilbert de Graaf (original work)
Reviewed by: rwatson (locking), silence from fenner,
net@ (but with encouragement)
2007-06-12 16:24:56 +00:00
|
|
|
* This structure is lazy-allocated.
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
|
|
|
struct ip_moptions {
|
|
|
|
struct ifnet *imo_multicast_ifp; /* ifp for outgoing multicasts */
|
2001-06-11 12:39:29 +00:00
|
|
|
struct in_addr imo_multicast_addr; /* ifindex/addr on MULTICAST_IF */
|
2006-05-14 14:22:49 +00:00
|
|
|
u_long imo_multicast_vif; /* vif num outgoing multicasts */
|
1994-05-24 10:09:53 +00:00
|
|
|
u_char imo_multicast_ttl; /* TTL for outgoing multicasts */
|
|
|
|
u_char imo_multicast_loop; /* 1 => hear sends if a member */
|
|
|
|
u_short imo_num_memberships; /* no. memberships this socket */
|
2006-05-14 14:22:49 +00:00
|
|
|
u_short imo_max_memberships; /* max memberships this socket */
|
|
|
|
struct in_multi **imo_membership; /* group memberships */
|
Import rewrite of IPv4 socket multicast layer to support source-specific
and protocol-independent host mode multicast. The code is written to
accomodate IPv6, IGMPv3 and MLDv2 with only a little additional work.
This change only pertains to FreeBSD's use as a multicast end-station and
does not concern multicast routing; for an IGMPv3/MLDv2 router
implementation, consider the XORP project.
The work is based on Wilbert de Graaf's IGMPv3 code drop for FreeBSD 4.6,
which is available at: http://www.kloosterhof.com/wilbert/igmpv3.html
Summary
* IPv4 multicast socket processing is now moved out of ip_output.c
into a new module, in_mcast.c.
* The in_mcast.c module implements the IPv4 legacy any-source API in
terms of the protocol-independent source-specific API.
* Source filters are lazy allocated as the common case does not use them.
They are part of per inpcb state and are covered by the inpcb lock.
* struct ip_mreqn is now supported to allow applications to specify
multicast joins by interface index in the legacy IPv4 any-source API.
* In UDP, an incoming multicast datagram only requires that the source
port matches the 4-tuple if the socket was already bound by source port.
An unbound socket SHOULD be able to receive multicasts sent from an
ephemeral source port.
* The UDP socket multicast filter mode defaults to exclusive, that is,
sources present in the per-socket list will be blocked from delivery.
* The RFC 3678 userland functions have been added to libc: setsourcefilter,
getsourcefilter, setipv4sourcefilter, getipv4sourcefilter.
* Definitions for IGMPv3 are merged but not yet used.
* struct sockaddr_storage is now referenced from <netinet/in.h>. It
is therefore defined there if not already declared in the same way
as for the C99 types.
* The RFC 1724 hack (specify 0.0.0.0/8 addresses to IP_MULTICAST_IF
which are then interpreted as interface indexes) is now deprecated.
* A patch for the Rhyolite.com routed in the FreeBSD base system
is available in the -net archives. This only affects individuals
running RIPv1 or RIPv2 via point-to-point and/or unnumbered interfaces.
* Make IPv6 detach path similar to IPv4's in code flow; functionally same.
* Bump __FreeBSD_version to 700048; see UPDATING.
This work was financially supported by another FreeBSD committer.
Obtained from: p4://bms_netdev
Submitted by: Wilbert de Graaf (original work)
Reviewed by: rwatson (locking), silence from fenner,
net@ (but with encouragement)
2007-06-12 16:24:56 +00:00
|
|
|
struct in_mfilter *imo_mfilters; /* source filters */
|
2018-05-20 00:22:28 +00:00
|
|
|
struct epoch_context imo_epoch_ctx;
|
1994-05-24 10:09:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ipstat {
|
2013-04-08 19:57:21 +00:00
|
|
|
uint64_t ips_total; /* total packets received */
|
|
|
|
uint64_t ips_badsum; /* checksum bad */
|
|
|
|
uint64_t ips_tooshort; /* packet too short */
|
|
|
|
uint64_t ips_toosmall; /* not enough data */
|
|
|
|
uint64_t ips_badhlen; /* ip header length < data size */
|
|
|
|
uint64_t ips_badlen; /* ip length < ip header length */
|
|
|
|
uint64_t ips_fragments; /* fragments received */
|
|
|
|
uint64_t ips_fragdropped; /* frags dropped (dups, out of space) */
|
|
|
|
uint64_t ips_fragtimeout; /* fragments timed out */
|
|
|
|
uint64_t ips_forward; /* packets forwarded */
|
|
|
|
uint64_t ips_fastforward; /* packets fast forwarded */
|
|
|
|
uint64_t ips_cantforward; /* packets rcvd for unreachable dest */
|
|
|
|
uint64_t ips_redirectsent; /* packets forwarded on same net */
|
|
|
|
uint64_t ips_noproto; /* unknown or unsupported protocol */
|
|
|
|
uint64_t ips_delivered; /* datagrams delivered to upper level*/
|
|
|
|
uint64_t ips_localout; /* total ip packets generated here */
|
|
|
|
uint64_t ips_odropped; /* lost packets due to nobufs, etc. */
|
|
|
|
uint64_t ips_reassembled; /* total packets reassembled ok */
|
|
|
|
uint64_t ips_fragmented; /* datagrams successfully fragmented */
|
|
|
|
uint64_t ips_ofragments; /* output fragments created */
|
|
|
|
uint64_t ips_cantfrag; /* don't fragment flag was set, etc. */
|
|
|
|
uint64_t ips_badoptions; /* error in option processing */
|
|
|
|
uint64_t ips_noroute; /* packets discarded due to no route */
|
|
|
|
uint64_t ips_badvers; /* ip version != 4 */
|
|
|
|
uint64_t ips_rawout; /* total raw ip packets generated */
|
|
|
|
uint64_t ips_toolong; /* ip length > max ip packet size */
|
|
|
|
uint64_t ips_notmember; /* multicasts for unregistered grps */
|
|
|
|
uint64_t ips_nogif; /* no match gif found */
|
|
|
|
uint64_t ips_badaddr; /* invalid address on header */
|
1994-05-24 10:09:53 +00:00
|
|
|
};
|
|
|
|
|
1999-12-29 04:46:21 +00:00
|
|
|
#ifdef _KERNEL
|
1998-07-13 12:20:07 +00:00
|
|
|
|
2013-04-08 19:57:21 +00:00
|
|
|
#include <sys/counter.h>
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
#include <net/vnet.h>
|
|
|
|
|
2013-07-09 09:43:03 +00:00
|
|
|
VNET_PCPUSTAT_DECLARE(struct ipstat, ipstat);
|
2009-08-02 19:43:32 +00:00
|
|
|
/*
|
|
|
|
* In-kernel consumers can use these accessor macros directly to update
|
|
|
|
* stats.
|
|
|
|
*/
|
2013-07-09 09:43:03 +00:00
|
|
|
#define IPSTAT_ADD(name, val) \
|
|
|
|
VNET_PCPUSTAT_ADD(struct ipstat, ipstat, name, (val))
|
2013-04-12 16:29:15 +00:00
|
|
|
#define IPSTAT_SUB(name, val) IPSTAT_ADD(name, -(val))
|
2009-04-11 23:35:20 +00:00
|
|
|
#define IPSTAT_INC(name) IPSTAT_ADD(name, 1)
|
2013-04-12 16:29:15 +00:00
|
|
|
#define IPSTAT_DEC(name) IPSTAT_SUB(name, 1)
|
2009-04-11 23:35:20 +00:00
|
|
|
|
2009-08-02 19:43:32 +00:00
|
|
|
/*
|
|
|
|
* Kernel module consumers must use this accessor macro.
|
|
|
|
*/
|
|
|
|
void kmod_ipstat_inc(int statnum);
|
2013-07-09 09:43:03 +00:00
|
|
|
#define KMOD_IPSTAT_INC(name) \
|
|
|
|
kmod_ipstat_inc(offsetof(struct ipstat, name) / sizeof(uint64_t))
|
2009-08-02 19:43:32 +00:00
|
|
|
void kmod_ipstat_dec(int statnum);
|
2013-07-09 09:43:03 +00:00
|
|
|
#define KMOD_IPSTAT_DEC(name) \
|
|
|
|
kmod_ipstat_dec(offsetof(struct ipstat, name) / sizeof(uint64_t))
|
2009-08-02 19:43:32 +00:00
|
|
|
|
Import rewrite of IPv4 socket multicast layer to support source-specific
and protocol-independent host mode multicast. The code is written to
accomodate IPv6, IGMPv3 and MLDv2 with only a little additional work.
This change only pertains to FreeBSD's use as a multicast end-station and
does not concern multicast routing; for an IGMPv3/MLDv2 router
implementation, consider the XORP project.
The work is based on Wilbert de Graaf's IGMPv3 code drop for FreeBSD 4.6,
which is available at: http://www.kloosterhof.com/wilbert/igmpv3.html
Summary
* IPv4 multicast socket processing is now moved out of ip_output.c
into a new module, in_mcast.c.
* The in_mcast.c module implements the IPv4 legacy any-source API in
terms of the protocol-independent source-specific API.
* Source filters are lazy allocated as the common case does not use them.
They are part of per inpcb state and are covered by the inpcb lock.
* struct ip_mreqn is now supported to allow applications to specify
multicast joins by interface index in the legacy IPv4 any-source API.
* In UDP, an incoming multicast datagram only requires that the source
port matches the 4-tuple if the socket was already bound by source port.
An unbound socket SHOULD be able to receive multicasts sent from an
ephemeral source port.
* The UDP socket multicast filter mode defaults to exclusive, that is,
sources present in the per-socket list will be blocked from delivery.
* The RFC 3678 userland functions have been added to libc: setsourcefilter,
getsourcefilter, setipv4sourcefilter, getipv4sourcefilter.
* Definitions for IGMPv3 are merged but not yet used.
* struct sockaddr_storage is now referenced from <netinet/in.h>. It
is therefore defined there if not already declared in the same way
as for the C99 types.
* The RFC 1724 hack (specify 0.0.0.0/8 addresses to IP_MULTICAST_IF
which are then interpreted as interface indexes) is now deprecated.
* A patch for the Rhyolite.com routed in the FreeBSD base system
is available in the -net archives. This only affects individuals
running RIPv1 or RIPv2 via point-to-point and/or unnumbered interfaces.
* Make IPv6 detach path similar to IPv4's in code flow; functionally same.
* Bump __FreeBSD_version to 700048; see UPDATING.
This work was financially supported by another FreeBSD committer.
Obtained from: p4://bms_netdev
Submitted by: Wilbert de Graaf (original work)
Reviewed by: rwatson (locking), silence from fenner,
net@ (but with encouragement)
2007-06-12 16:24:56 +00:00
|
|
|
/* flags passed to ip_output as last parameter */
|
|
|
|
#define IP_FORWARDING 0x1 /* most of ip header exists */
|
|
|
|
#define IP_RAWOUTPUT 0x2 /* raw ip header exists */
|
|
|
|
#define IP_SENDONES 0x4 /* send all-ones broadcast */
|
|
|
|
#define IP_SENDTOIF 0x8 /* send on specific ifnet */
|
2007-04-04 15:30:31 +00:00
|
|
|
#define IP_ROUTETOIF SO_DONTROUTE /* 0x10 bypass routing tables */
|
|
|
|
#define IP_ALLOWBROADCAST SO_BROADCAST /* 0x20 can send broadcast packets */
|
2014-09-09 00:19:02 +00:00
|
|
|
#define IP_NODEFAULTFLOWID 0x40 /* Don't set the flowid from inp */
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2005-07-02 23:13:31 +00:00
|
|
|
#ifdef __NO_STRICT_ALIGNMENT
|
|
|
|
#define IP_HDR_ALIGNED_P(ip) 1
|
|
|
|
#else
|
|
|
|
#define IP_HDR_ALIGNED_P(ip) ((((intptr_t) (ip)) & 3) == 0)
|
|
|
|
#endif
|
|
|
|
|
1998-08-23 03:07:17 +00:00
|
|
|
struct ip;
|
1996-11-12 10:02:09 +00:00
|
|
|
struct inpcb;
|
1996-10-15 16:54:47 +00:00
|
|
|
struct route;
|
1998-08-23 03:07:17 +00:00
|
|
|
struct sockopt;
|
2018-05-05 22:40:40 +00:00
|
|
|
struct inpcbinfo;
|
1996-10-15 16:54:47 +00:00
|
|
|
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
VNET_DECLARE(int, ip_defttl); /* default IP ttl */
|
|
|
|
VNET_DECLARE(int, ipforwarding); /* ip forwarding */
|
|
|
|
#ifdef IPSTEALTH
|
|
|
|
VNET_DECLARE(int, ipstealth); /* stealth forwarding */
|
|
|
|
#endif
|
2010-04-29 11:52:42 +00:00
|
|
|
extern u_char ip_protox[];
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
VNET_DECLARE(struct socket *, ip_rsvpd); /* reservation protocol daemon*/
|
|
|
|
VNET_DECLARE(struct socket *, ip_mrouter); /* multicast routing daemon */
|
2010-04-29 11:52:42 +00:00
|
|
|
extern int (*legal_vif_num)(int);
|
|
|
|
extern u_long (*ip_mcast_src)(int);
|
|
|
|
VNET_DECLARE(int, rsvp_on);
|
2012-10-10 19:06:11 +00:00
|
|
|
VNET_DECLARE(int, drop_redirect);
|
2010-04-29 11:52:42 +00:00
|
|
|
extern struct pr_usrreqs rip_usrreqs;
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
|
2009-07-16 21:13:04 +00:00
|
|
|
#define V_ip_id VNET(ip_id)
|
|
|
|
#define V_ip_defttl VNET(ip_defttl)
|
|
|
|
#define V_ipforwarding VNET(ipforwarding)
|
2003-11-15 01:45:56 +00:00
|
|
|
#ifdef IPSTEALTH
|
2009-07-16 21:13:04 +00:00
|
|
|
#define V_ipstealth VNET(ipstealth)
|
2003-11-15 01:45:56 +00:00
|
|
|
#endif
|
2009-07-16 21:13:04 +00:00
|
|
|
#define V_ip_rsvpd VNET(ip_rsvpd)
|
|
|
|
#define V_ip_mrouter VNET(ip_mrouter)
|
2010-04-29 11:52:42 +00:00
|
|
|
#define V_rsvp_on VNET(rsvp_on)
|
2012-10-10 19:06:11 +00:00
|
|
|
#define V_drop_redirect VNET(drop_redirect)
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2018-05-20 00:22:28 +00:00
|
|
|
void inp_freemoptions(struct ip_moptions *);
|
Import rewrite of IPv4 socket multicast layer to support source-specific
and protocol-independent host mode multicast. The code is written to
accomodate IPv6, IGMPv3 and MLDv2 with only a little additional work.
This change only pertains to FreeBSD's use as a multicast end-station and
does not concern multicast routing; for an IGMPv3/MLDv2 router
implementation, consider the XORP project.
The work is based on Wilbert de Graaf's IGMPv3 code drop for FreeBSD 4.6,
which is available at: http://www.kloosterhof.com/wilbert/igmpv3.html
Summary
* IPv4 multicast socket processing is now moved out of ip_output.c
into a new module, in_mcast.c.
* The in_mcast.c module implements the IPv4 legacy any-source API in
terms of the protocol-independent source-specific API.
* Source filters are lazy allocated as the common case does not use them.
They are part of per inpcb state and are covered by the inpcb lock.
* struct ip_mreqn is now supported to allow applications to specify
multicast joins by interface index in the legacy IPv4 any-source API.
* In UDP, an incoming multicast datagram only requires that the source
port matches the 4-tuple if the socket was already bound by source port.
An unbound socket SHOULD be able to receive multicasts sent from an
ephemeral source port.
* The UDP socket multicast filter mode defaults to exclusive, that is,
sources present in the per-socket list will be blocked from delivery.
* The RFC 3678 userland functions have been added to libc: setsourcefilter,
getsourcefilter, setipv4sourcefilter, getipv4sourcefilter.
* Definitions for IGMPv3 are merged but not yet used.
* struct sockaddr_storage is now referenced from <netinet/in.h>. It
is therefore defined there if not already declared in the same way
as for the C99 types.
* The RFC 1724 hack (specify 0.0.0.0/8 addresses to IP_MULTICAST_IF
which are then interpreted as interface indexes) is now deprecated.
* A patch for the Rhyolite.com routed in the FreeBSD base system
is available in the -net archives. This only affects individuals
running RIPv1 or RIPv2 via point-to-point and/or unnumbered interfaces.
* Make IPv6 detach path similar to IPv4's in code flow; functionally same.
* Bump __FreeBSD_version to 700048; see UPDATING.
This work was financially supported by another FreeBSD committer.
Obtained from: p4://bms_netdev
Submitted by: Wilbert de Graaf (original work)
Reviewed by: rwatson (locking), silence from fenner,
net@ (but with encouragement)
2007-06-12 16:24:56 +00:00
|
|
|
int inp_getmoptions(struct inpcb *, struct sockopt *);
|
|
|
|
int inp_setmoptions(struct inpcb *, struct sockopt *);
|
|
|
|
|
2007-04-04 15:30:31 +00:00
|
|
|
int ip_ctloutput(struct socket *, struct sockopt *sopt);
|
|
|
|
void ip_drain(void);
|
|
|
|
int ip_fragment(struct ip *ip, struct mbuf **m_frag, int mtu,
|
2012-10-26 21:06:33 +00:00
|
|
|
u_long if_hwassist_flags);
|
2007-04-04 15:30:31 +00:00
|
|
|
void ip_forward(struct mbuf *m, int srcrt);
|
|
|
|
void ip_init(void);
|
|
|
|
extern int
|
|
|
|
(*ip_mforward)(struct ip *, struct ifnet *, struct mbuf *,
|
|
|
|
struct ip_moptions *);
|
|
|
|
int ip_output(struct mbuf *,
|
2002-10-16 01:54:46 +00:00
|
|
|
struct mbuf *, struct route *, int, struct ip_moptions *,
|
|
|
|
struct inpcb *);
|
2010-09-02 17:43:44 +00:00
|
|
|
int ipproto_register(short);
|
|
|
|
int ipproto_unregister(short);
|
2004-08-17 22:05:54 +00:00
|
|
|
struct mbuf *
|
2007-04-04 15:30:31 +00:00
|
|
|
ip_reass(struct mbuf *);
|
|
|
|
void ip_savecontrol(struct inpcb *, struct mbuf **, struct ip *,
|
|
|
|
struct mbuf *);
|
|
|
|
void ip_slowtimo(void);
|
2015-04-01 22:26:39 +00:00
|
|
|
void ip_fillid(struct ip *);
|
2002-06-23 09:03:42 +00:00
|
|
|
int rip_ctloutput(struct socket *, struct sockopt *);
|
|
|
|
void rip_ctlinput(int, struct sockaddr *, void *);
|
|
|
|
void rip_init(void);
|
2014-08-08 01:57:15 +00:00
|
|
|
int rip_input(struct mbuf **, int *, int);
|
2014-08-15 02:43:02 +00:00
|
|
|
int rip_output(struct mbuf *, struct socket *, ...);
|
2014-08-08 01:57:15 +00:00
|
|
|
int ipip_input(struct mbuf **, int *, int);
|
|
|
|
int rsvp_input(struct mbuf **, int *, int);
|
2002-03-19 21:25:46 +00:00
|
|
|
int ip_rsvp_init(struct socket *);
|
|
|
|
int ip_rsvp_done(void);
|
Massive cleanup of the ip_mroute code.
No functional changes, but:
+ the mrouting module now should behave the same as the compiled-in
version (it did not before, some of the rsvp code was not loaded
properly);
+ netinet/ip_mroute.c is now truly optional;
+ removed some redundant/unused code;
+ changed many instances of '0' to NULL and INADDR_ANY as appropriate;
+ removed several static variables to make the code more SMP-friendly;
+ fixed some minor bugs in the mrouting code (mostly, incorrect return
values from functions).
This commit is also a prerequisite to the addition of support for PIM,
which i would like to put in before DP2 (it does not change any of
the existing APIs, anyways).
Note, in the process we found out that some device drivers fail to
properly handle changes in IFF_ALLMULTI, leading to interesting
behaviour when a multicast router is started. This bug is not
corrected by this commit, and will be fixed with a separate commit.
Detailed changes:
--------------------
netinet/ip_mroute.c all the above.
conf/files make ip_mroute.c optional
net/route.c fix mrt_ioctl hook
netinet/ip_input.c fix ip_mforward hook, move rsvp_input() here
together with other rsvp code, and a couple
of indentation fixes.
netinet/ip_output.c fix ip_mforward and ip_mcast_src hooks
netinet/ip_var.h rsvp function hooks
netinet/raw_ip.c hooks for mrouting and rsvp functions, plus
interface cleanup.
netinet/ip_mroute.h remove an unused and optional field from a struct
Most of the code is from Pavlin Radoslavov and the XORP project
Reviewed by: sam
MFC after: 1 week
2002-11-15 22:53:53 +00:00
|
|
|
extern int (*ip_rsvp_vif)(struct socket *, struct sockopt *);
|
|
|
|
extern void (*ip_rsvp_force_done)(struct socket *);
|
2014-08-08 01:57:15 +00:00
|
|
|
extern int (*rsvp_input_p)(struct mbuf **, int *, int);
|
Massive cleanup of the ip_mroute code.
No functional changes, but:
+ the mrouting module now should behave the same as the compiled-in
version (it did not before, some of the rsvp code was not loaded
properly);
+ netinet/ip_mroute.c is now truly optional;
+ removed some redundant/unused code;
+ changed many instances of '0' to NULL and INADDR_ANY as appropriate;
+ removed several static variables to make the code more SMP-friendly;
+ fixed some minor bugs in the mrouting code (mostly, incorrect return
values from functions).
This commit is also a prerequisite to the addition of support for PIM,
which i would like to put in before DP2 (it does not change any of
the existing APIs, anyways).
Note, in the process we found out that some device drivers fail to
properly handle changes in IFF_ALLMULTI, leading to interesting
behaviour when a multicast router is started. This bug is not
corrected by this commit, and will be fixed with a separate commit.
Detailed changes:
--------------------
netinet/ip_mroute.c all the above.
conf/files make ip_mroute.c optional
net/route.c fix mrt_ioctl hook
netinet/ip_input.c fix ip_mforward hook, move rsvp_input() here
together with other rsvp code, and a couple
of indentation fixes.
netinet/ip_output.c fix ip_mforward and ip_mcast_src hooks
netinet/ip_var.h rsvp function hooks
netinet/raw_ip.c hooks for mrouting and rsvp functions, plus
interface cleanup.
netinet/ip_mroute.h remove an unused and optional field from a struct
Most of the code is from Pavlin Radoslavov and the XORP project
Reviewed by: sam
MFC after: 1 week
2002-11-15 22:53:53 +00:00
|
|
|
|
New pfil(9) KPI together with newborn pfil API and control utility.
The KPI have been reviewed and cleansed of features that were planned
back 20 years ago and never implemented. The pfil(9) internals have
been made opaque to protocols with only returned types and function
declarations exposed. The KPI is made more strict, but at the same time
more extensible, as kernel uses same command structures that userland
ioctl uses.
In nutshell [KA]PI is about declaring filtering points, declaring
filters and linking and unlinking them together.
New [KA]PI makes it possible to reconfigure pfil(9) configuration:
change order of hooks, rehook filter from one filtering point to a
different one, disconnect a hook on output leaving it on input only,
prepend/append a filter to existing list of filters.
Now it possible for a single packet filter to provide multiple rulesets
that may be linked to different points. Think of per-interface ACLs in
Cisco or Juniper. None of existing packet filters yet support that,
however limited usage is already possible, e.g. default ruleset can
be moved to single interface, as soon as interface would pride their
filtering points.
Another future feature is possiblity to create pfil heads, that provide
not an mbuf pointer but just a memory pointer with length. That would
allow filtering at very early stages of a packet lifecycle, e.g. when
packet has just been received by a NIC and no mbuf was yet allocated.
Differential Revision: https://reviews.freebsd.org/D18951
2019-01-31 23:01:03 +00:00
|
|
|
VNET_DECLARE(struct pfil_head *, inet_pfil_head);
|
|
|
|
#define V_inet_pfil_head VNET(inet_pfil_head)
|
|
|
|
#define PFIL_INET_NAME "inet"
|
2003-09-23 17:54:04 +00:00
|
|
|
|
2000-05-21 21:26:06 +00:00
|
|
|
void in_delayed_cksum(struct mbuf *m);
|
|
|
|
|
2010-01-07 10:39:15 +00:00
|
|
|
/* Hooks for ipfw, dummynet, divert etc. Most are declared in raw_ip.c */
|
|
|
|
/*
|
|
|
|
* Reference to an ipfw or packet filter rule that can be carried
|
|
|
|
* outside critical sections.
|
|
|
|
* A rule is identified by rulenum:rule_id which is ordered.
|
|
|
|
* In version chain_id the rule can be found in slot 'slot', so
|
|
|
|
* we don't need a lookup if chain_id == chain->id.
|
|
|
|
*
|
|
|
|
* On exit from the firewall this structure refers to the rule after
|
|
|
|
* the matching one (slot points to the new rule; rulenum:rule_id-1
|
|
|
|
* is the matching rule), and additional info (e.g. info often contains
|
|
|
|
* the insn argument or tablearg in the low 16 bits, in host format).
|
|
|
|
* On entry, the structure is valid if slot>0, and refers to the starting
|
|
|
|
* rules. 'info' contains the reason for reinject, e.g. divert port,
|
|
|
|
* divert direction, and so on.
|
|
|
|
*/
|
|
|
|
struct ipfw_rule_ref {
|
|
|
|
uint32_t slot; /* slot for matching rule */
|
|
|
|
uint32_t rulenum; /* matching rule number */
|
|
|
|
uint32_t rule_id; /* matching rule id */
|
|
|
|
uint32_t chain_id; /* ruleset id */
|
|
|
|
uint32_t info; /* see below */
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
IPFW_INFO_MASK = 0x0000ffff,
|
|
|
|
IPFW_INFO_OUT = 0x00000000, /* outgoing, just for convenience */
|
|
|
|
IPFW_INFO_IN = 0x80000000, /* incoming, overloads dir */
|
|
|
|
IPFW_ONEPASS = 0x40000000, /* One-pass, do not reinject */
|
|
|
|
IPFW_IS_MASK = 0x30000000, /* which source ? */
|
|
|
|
IPFW_IS_DIVERT = 0x20000000,
|
|
|
|
IPFW_IS_DUMMYNET =0x10000000,
|
2015-07-18 15:28:32 +00:00
|
|
|
IPFW_IS_PIPE = 0x08000000, /* pipe=1, queue = 0 */
|
2010-01-07 10:39:15 +00:00
|
|
|
};
|
|
|
|
#define MTAG_IPFW 1148380143 /* IPFW-tagged cookie */
|
|
|
|
#define MTAG_IPFW_RULE 1262273568 /* rule reference */
|
2011-06-29 10:06:58 +00:00
|
|
|
#define MTAG_IPFW_CALL 1308397630 /* call stack */
|
2010-01-07 10:39:15 +00:00
|
|
|
|
2009-06-05 13:44:30 +00:00
|
|
|
struct ip_fw_args;
|
2009-10-11 05:59:43 +00:00
|
|
|
typedef int (*ip_fw_chk_ptr_t)(struct ip_fw_args *args);
|
|
|
|
typedef int (*ip_fw_ctl_ptr_t)(struct sockopt *);
|
|
|
|
VNET_DECLARE(ip_fw_ctl_ptr_t, ip_fw_ctl_ptr);
|
|
|
|
#define V_ip_fw_ctl_ptr VNET(ip_fw_ctl_ptr)
|
|
|
|
|
2010-01-07 10:39:15 +00:00
|
|
|
/* Divert hooks. */
|
|
|
|
extern void (*ip_divert_ptr)(struct mbuf *m, int incoming);
|
|
|
|
/* ng_ipfw hooks -- XXX make it the same as divert and dummynet */
|
|
|
|
extern int (*ng_ipfw_input_p)(struct mbuf **, int,
|
|
|
|
struct ip_fw_args *, int);
|
|
|
|
|
2009-06-05 13:44:30 +00:00
|
|
|
extern int (*ip_dn_ctl_ptr)(struct sockopt *);
|
2010-01-07 10:39:15 +00:00
|
|
|
extern int (*ip_dn_io_ptr)(struct mbuf **, int, struct ip_fw_args *);
|
1999-12-29 04:46:21 +00:00
|
|
|
#endif /* _KERNEL */
|
1994-08-21 05:27:42 +00:00
|
|
|
|
1998-07-13 12:20:07 +00:00
|
|
|
#endif /* !_NETINET_IP_VAR_H_ */
|