Commit Graph
1685 Commits
Author SHA1 Message Date
Enji Cooper d06e34c827 MFC r318255:
Add missing braces around MCAST_EXCLUDE check when KTR support is
compiled into the kernel

This ensures that .iss_asm (the number of ASM listeners) isn't incorrectly
decremented for MLD-layer source datagrams when inspecting im*s_st[1]
(the second state in the structure).

PR:		217509 [1]
2017-07-18 16:58:54 +00:00
Michael Tuexen ec396d217e MFC r318649:
The connect() system call should return -1 and set errno to EAFNOSUPPORT
if it is called on a TCP socket
 * with an IPv6 address and the socket is bound to an
   IPv4-mapped IPv6 address.
 * with an IPv4-mapped IPv6 address and the socket is bound to an
   IPv6 address.
Thanks to Jonathan T. Leighton for reporting this issue.

Reviewed by:		bz, gnn
Differential Revision:	https://reviews.freebsd.org/D9163
2017-06-01 10:03:41 +00:00
Michael Tuexen b9873b1ee7 MFC 317464:
Fix an issue with MTU calculation if an ICMP message is received
for an SCTP/UDP packet.
2017-06-01 08:58:39 +00:00
Michael Tuexen c9f6f004a2 MFC r317457:
Use consistently uint32_t for mtu values.

This does not change functionality, but this cleanup is need for further
improvements of ICMP handling.
2017-06-01 08:48:16 +00:00
Navdeep Parhar 55acd335e1 MFC r318124:
ip6_output runs with the inp lock held, just like ip_output.
2017-05-25 01:14:34 +00:00
Kristof Provost e73df7eda3 MFC r317186
pf: Fix possible incorrect IPv6 fragmentation

When forwarding pf tracks the size of the largest fragment in a fragmented
packet, and refragments based on this size.
It failed to ensure that this size was a multiple of 8 (as is required for all
but the last fragment), so it could end up generating incorrect fragments.

For example, if we received an 8 byte and 12 byte fragment pf would emit a first
fragment with 12 bytes of payload and the final fragment would claim to be at
offset 8 (not 12).

We now assert that the fragment size is a multiple of 8 in ip6_fragment(), so
other users won't make the same mistake.

Reported by:	Antonios Atlasis <aatlasis at secfu net>
2017-04-23 08:58:50 +00:00
Alan Somers 65f4ff4020 MFC r313025, r313395, r314113, r314442, r315458, r315656
r313025:
Add tests for multi-fib IPv6 routing

PR:		196361
Submitted by:	[email protected]
Reported by:	Jason Healy <[email protected]>
MFC after:	4 weeks
Sponsored by:	Spectra Logic Corp

r313395:
Add fibs_test:udp_dontroute6, another IPv6 multi-FIB test

PR:		196361
MFC after:	3 weeks
Sponsored by:	Spectra Logic Corp

r314113:
Remove tests/sys/netinet/fibs_tests's dependency on net/socat

Instead of bridging two tap interfaces with socat, just use an epair pair.

MFC after:	3 weeks
Sponsored by:	Spectra Logic Corp

r314442:
Add an ATF test for IPv6 SLAAC with multiple fibs

Tests that an interface can get a SLAAC address and that it inserts its
routes into the correct fib. Does not test anything to do with NDP.

PR:		196361
Reviewed by:	Erick Turnquist <[email protected]>
MFC after:	3 weeks
Sponsored by:	Spectra Logic Corp
Differential Revision:	https://reviews.freebsd.org/D9776

r315458:
Constrain IPv6 routes to single FIBs when net.add_addr_allfibs=0

sys/netinet6/icmp6.c
	Use the interface's FIB for source address selection in ICMPv6 error
	responses.

sys/netinet6/in6.c
	In in6_newaddrmsg, announce arrival of local addresses on the
	interface's FIB only.  In in6_lltable_rtcheck, use a per-fib ND6
	cache instead of a single cache.

sys/netinet6/in6_src.c
	In in6_selectsrc, use the caller's fib instead of the default fib.
	In in6_selectsrc_socket, remove a superfluous check.

sys/netinet6/nd6.c
	In nd6_lle_event, use the interface's fib for routing socket
	messages.  In nd6_is_new_addr_neighbor, check all FIBs when trying
	to determine whether an address is a neighbor.  Also, simplify the
	code for point to point interfaces.

sys/netinet6/nd6.h
sys/netinet6/nd6.c
sys/netinet6/nd6_rtr.c
	Make defrouter_select fib-aware, and make all of its callers pass in
	the interface fib.

sys/netinet6/nd6_nbr.c
	When inputting a Neighbor Solicitation packet, consider the
	interface fib instead of the default fib for DAD.  Output NS and
	Neighbor Advertisement packets on the correct fib.

sys/netinet6/nd6_rtr.c
	Allow installing the same host route on different interfaces in
	different FIBs.  If rt_add_addr_allfibs=0, only install or delete
	the prefix route on the interface fib.

tests/sys/netinet/fibs_test.sh
	Clear some expected failures, but add a skip for the newly revealed
	BUG217871.

PR:		196361
Submitted by:	Erick Turnquist <[email protected]>
Reported by:	Jason Healy <[email protected]>
Reviewed by:	asomers
MFC after:	3 weeks
Sponsored by:	Spectra Logic Corp
Differential Revision:	https://reviews.freebsd.org/D9451

r315656:
Fix back-to-back runs of sys/netinet/fibs_test;slaac_on_nondefault_fib6

This test was failing if run twice because rtadvd takes too long to die.
The rtadvd process from the first run was still running when the
second run created its interfaces.  The solution is to use SIGKILL during
the cleanup instead of SIGTERM so rtadvd will die faster.

While I'm here, randomize the addresses used for the test, which makes bugs
like this easier to spot, and fix the cleanup order to be the opposite of
the setup order

PR:		217871
MFC after:	18 days
X-MFC-With:	315458
Sponsored by:	Spectra Logic Corp
2017-04-17 20:13:20 +00:00
Steven Hartland 8feec35a2d MFC r316313, r316328:
Allow explicitly assigned IPv4 & IPv6 loopback addresses to be used in
jails.

Relnotes:	Yes
Sponsored by:	Multiplay
2017-04-14 22:02:08 +00:00
Steven Hartland 89ea4839ca MFC r303863:
Move IPv4 & IPv6 specific jail functions to netinet and netinet6 files.

Sponsored by:	Multiplay
2017-04-14 21:49:20 +00:00
Mark Johnston 505053ffdf MFC r306829, r310286, r311695:
Lock the ND prefix list and add refcounting for prefixes.
2017-04-11 18:48:17 +00:00
Mike Karels 38071304a8 Fix reference count leak with L2 caching.
MFC r315956

ip_forward, TCP/IPv6, and probably SCTP leaked references to L2 cache
entry because they used their own routes on the stack, not in_pcb routes.
The original model for route caching was callers that provided a route
structure to ip{,6}input() would keep the route, and this model was used
for L2 caching as well. Instead, change L2 caching to be done by default
only when using a route structure in the in_pcb; the pcb deallocation
code frees L2 as well as L3 cacches. A separate change will add route
caching to TCP/IPv6.

Another suggestion was to have the transport protocols indicate willingness
to use L2 caching, but this approach keeps the changes in the network
level

Reviewed by:    ae gnn
MFC after:      2 weeks
Differential Revision:  https://reviews.freebsd.org/D10059
2017-04-10 01:26:12 +00:00
Andrey V. Elsukov 4c2ac843d9 MFC r304041:
Move logging via BPF support into separate file.

  * make interface cloner VNET-aware;
  * simplify cloner code and use if_clone_simple();
  * migrate LOGIF_LOCK() to rmlock;
  * add ipfw_bpf_mtap2() function to pass mbuf to BPF;
  * introduce new additional ipfwlog0 pseudo interface. It differs from
    ipfw0 by DLT type used in bpfattach. This interface is intended to
    used by ipfw modules to dump packets with additional info attached.
    Currently pflog format is used. ipfw_bpf_mtap2() function uses second
    argument to determine which interface use for dumping. If dlen is equal
    to ETHER_HDR_LEN it uses old ipfw0 interface, if dlen is equal to
    PFLOG_HDRLEN - ipfwlog0 will be used.

  Obtained from:	Yandex LLC
  Sponsored by:	Yandex LLC

MFC r304043:
  Add three helper function to manage tables from external modules.

  ipfw_objhash_lookup_table_kidx does lookup kernel index of table;
  ipfw_ref_table/ipfw_unref_table takes and releases reference to table.

  Obtained from:	Yandex LLC
  Sponsored by:	Yandex LLC

MFC r304046, 304108:
  Add ipfw_nat64 module that implements stateless and stateful NAT64.

  The module works together with ipfw(4) and implemented as its external
  action module.

  Stateless NAT64 registers external action with name nat64stl. This
  keyword should be used to create NAT64 instance and to address this
  instance in rules. Stateless NAT64 uses two lookup tables with mapped
  IPv4->IPv6 and IPv6->IPv4 addresses to perform translation.

  A configuration of instance should looks like this:
   1. Create lookup tables:
   # ipfw table T46 create type addr valtype ipv6
   # ipfw table T64 create type addr valtype ipv4
   2. Fill T46 and T64 tables.
   3. Add rule to allow neighbor solicitation and advertisement:
   # ipfw add allow icmp6 from any to any icmp6types 135,136
   4. Create NAT64 instance:
   # ipfw nat64stl NAT create table4 T46 table6 T64
   5. Add rules that matches the traffic:
   # ipfw add nat64stl NAT ip from any to table(T46)
   # ipfw add nat64stl NAT ip from table(T64) to 64:ff9b::/96
   6. Configure DNS64 for IPv6 clients and add route to 64:ff9b::/96
      via NAT64 host.

  Stateful NAT64 registers external action with name nat64lsn. The only
  one option required to create nat64lsn instance - prefix4. It defines
  the pool of IPv4 addresses used for translation.

  A configuration of instance should looks like this:
   1. Add rule to allow neighbor solicitation and advertisement:
   # ipfw add allow icmp6 from any to any icmp6types 135,136
   2. Create NAT64 instance:
   # ipfw nat64lsn NAT create prefix4 A.B.C.D/28
   3. Add rules that matches the traffic:
   # ipfw add nat64lsn NAT ip from any to A.B.C.D/28
   # ipfw add nat64lsn NAT ip6 from any to 64:ff9b::/96
   4. Configure DNS64 for IPv6 clients and add route to 64:ff9b::/96
      via NAT64 host.

  Obtained from:	Yandex LLC
  Relnotes:	yes
  Sponsored by:	Yandex LLC
  Differential Revision:	https://reviews.freebsd.org/D6434

MFC r304048:
  Replace __noinline with special debug macro NAT64NOINLINE.

MFC r304061:
  Use %ju to print unsigned 64-bit value.

MFC r304076:
  Make statistics nat64lsn, nat64stl an nptv6 output netstat-like:
  "@value @description" and fix build due to -Wformat errors.

MFC r304378 (by bz):
  Try to fix gcc compilation errors (which are right).
  nat64_getlasthdr() returns an int, which can be -1 in case of error,
  storing the result in an uint8_t and then comparing to < 0 is not
  helpful.  Do what is done in the rest of the code and make proto an
  int here as well.

MFC r309187:
  Fix ICMPv6 Time Exceeded error message translation.

MFC r314718:
  Use new ipfw_lookup_table() in the nat64 too.

MFC r315204,315233:
  Use memset with structure size.
2017-04-03 08:50:54 +00:00
Andrey V. Elsukov 5770c16c44 MFC r303012:
Add ipfw_nptv6 module that implements Network Prefix Translation for IPv6
  as defined in RFC 6296. The module works together with ipfw(4) and
  implemented as its external action module. When it is loaded, it registers
  as eaction and can be used in rules. The usage pattern is similar to
  ipfw_nat(4). All matched by rule traffic goes to the NPT module.

  Reviewed by:	hrs
  Obtained from:	Yandex LLC
  Relnotes:	yes
  Sponsored by:	Yandex LLC
  Differential Revision:	https://reviews.freebsd.org/D6420

MFC r304049:
  Add `stats reset` command implementation to NPTv6 module
  to be able reset statistics counters.

  Obtained from:	Yandex LLC
  Sponsored by:	Yandex LLC

MFC r304076:
  Make statistics nat64lsn, nat64stl an nptv6 output netstat-like:
  "@value @description" and fix build due to -Wformat errors.

MFC r314507:
  Fix NPTv6 rule counters when one_pass is not enabled.

  Consider the rule matching when both @done and @retval values
  returned from ipfw_run_eaction() are zero. And modify ipfw_nptv6()
  to return IP_FW_DENY and @done=0 when addresses do not match.

  Obtained from:	Yandex LLC
  Sponsored by:	Yandex LLC
2017-04-03 07:30:47 +00:00
Andrey V. Elsukov 8e5a48ff55 MFC r304572 (by bz):
Remove the kernel optoion for IPSEC_FILTERTUNNEL, which was deprecated
  more than 7 years ago in favour of a sysctl in r192648.

MFC r305122:
  Remove redundant sanity checks from ipsec[46]_common_input_cb().

  This check already has been done in the each protocol callback.

MFC r309144,309174,309201 (by fabient):
  IPsec RFC6479 support for replay window sizes up to 2^32 - 32 packets.

  Since the previous algorithm, based on bit shifting, does not scale
  with large replay windows, the algorithm used here is based on
  RFC 6479: IPsec Anti-Replay Algorithm without Bit Shifting.
  The replay window will be fast to be updated, but will cost as many bits
  in RAM as its size.

  The previous implementation did not provide a lock on the replay window,
  which may lead to replay issues.

  Obtained from:	[email protected]
  Sponsored by:	Stormshield
  Differential Revision:	https://reviews.freebsd.org/D8468

MFC r309143,309146 (by fabient):
  In a dual processor system (2*6 cores) during IPSec throughput tests,
  we see a lot of contention on the arc4 lock, used to generate the IV
  of the ESP output packets.

  The idea of this patch is to split this mutex in order to reduce the
  contention on this lock.

  Update r309143 to prevent false sharing.

  Reviewed by:	delphij, markm, ache
  Approved by:	so
  Obtained from: [email protected]
  Sponsored by:	Stormshield
  Differential Revision:	https://reviews.freebsd.org/D8130

MFC r313330:
  Merge projects/ipsec into head/.

   Small summary
   -------------

  o Almost all IPsec releated code was moved into sys/netipsec.
  o New kernel modules added: ipsec.ko and tcpmd5.ko. New kernel
    option IPSEC_SUPPORT added. It enables support for loading
    and unloading of ipsec.ko and tcpmd5.ko kernel modules.
  o IPSEC_NAT_T option was removed. Now NAT-T support is enabled by
    default. The UDP_ENCAP_ESPINUDP_NON_IKE encapsulation type
    support was removed. Added TCP/UDP checksum handling for
    inbound packets that were decapsulated by transport mode SAs.
    setkey(8) modified to show run-time NAT-T configuration of SA.
  o New network pseudo interface if_ipsec(4) added. For now it is
    build as part of ipsec.ko module (or with IPSEC kernel).
    It implements IPsec virtual tunnels to create route-based VPNs.
  o The network stack now invokes IPsec functions using special
    methods. The only one header file <netipsec/ipsec_support.h>
    should be included to declare all the needed things to work
    with IPsec.
  o All IPsec protocols handlers (ESP/AH/IPCOMP protosw) were removed.
    Now these protocols are handled directly via IPsec methods.
  o TCP_SIGNATURE support was reworked to be more close to RFC.
  o PF_KEY SADB was reworked:
    - now all security associations stored in the single SPI namespace,
      and all SAs MUST have unique SPI.
    - several hash tables added to speed up lookups in SADB.
    - SADB now uses rmlock to protect access, and concurrent threads
      can do SA lookups in the same time.
    - many PF_KEY message handlers were reworked to reflect changes
      in SADB.
    - SADB_UPDATE message was extended to support new PF_KEY headers:
      SADB_X_EXT_NEW_ADDRESS_SRC and SADB_X_EXT_NEW_ADDRESS_DST. They
      can be used by IKE daemon to change SA addresses.
  o ipsecrequest and secpolicy structures were cardinally changed to
    avoid locking protection for ipsecrequest. Now we support
    only limited number (4) of bundled SAs, but they are supported
    for both INET and INET6.
  o INPCB security policy cache was introduced. Each PCB now caches
    used security policies to avoid SP lookup for each packet.
  o For inbound security policies added the mode, when the kernel does
    check for full history of applied IPsec transforms.
  o References counting rules for security policies and security
    associations were changed. The proper SA locking added into xform
    code.
  o xform code was also changed. Now it is possible to unregister xforms.
    tdb_xxx structures were changed and renamed to reflect changes in
    SADB/SPDB, and changed rules for locking and refcounting.

  Obtained from:	Yandex LLC
  Relnotes:	yes
  Sponsored by:	Yandex LLC
  Differential Revision:	https://reviews.freebsd.org/D9352

MFC r313331:
  Add removed headers into the ObsoleteFiles.inc.

MFC r313561 (by glebius):
  Move tcp_fields_to_net() static inline into tcp_var.h, just below its
  friend tcp_fields_to_host(). There is third party code that also uses
  this inline.

MFC r313697:
  Remove IPsec related PCB code from SCTP.

  The inpcb structure has inp_sp pointer that is initialized by
  ipsec_init_pcbpolicy() function. This pointer keeps strorage for IPsec
  security policies associated with a specific socket.
  An application can use IP_IPSEC_POLICY and IPV6_IPSEC_POLICY socket
  options to configure these security policies. Then ip[6]_output()
  uses inpcb pointer to specify that an outgoing packet is associated
  with some socket. And IPSEC_OUTPUT() method can use a security policy
  stored in the inp_sp. For inbound packet the protocol-specific input
  routine uses IPSEC_CHECK_POLICY() method to check that a packet conforms
  to inbound security policy configured in the inpcb.

  SCTP protocol doesn't specify inpcb for ip[6]_output() when it sends
  packets. Thus IPSEC_OUTPUT() method does not consider such packets as
  associated with some socket and can not apply security policies
  from inpcb, even if they are configured. Since IPSEC_CHECK_POLICY()
  method is called from protocol-specific input routine, it can specify
  inpcb pointer and associated with socket inbound policy will be
  checked. But there are two problems:
  1. Such check is asymmetric, becasue we can not apply security policy
  from inpcb for outgoing packet.
  2. IPSEC_CHECK_POLICY() expects that caller holds INPCB lock and
  access to inp_sp is protected. But for SCTP this is not correct,
  becasue SCTP uses own locks to protect inpcb.

  To fix these problems remove IPsec related PCB code from SCTP.
  This imply that IP_IPSEC_POLICY and IPV6_IPSEC_POLICY socket options
  will be not applicable to SCTP sockets. To be able correctly check
  inbound security policies for SCTP, mark its protocol header with
  the PR_LASTHDR flag.

  Differential Revision:	https://reviews.freebsd.org/D9538

MFC r313746:
  Add missing check to fix the build with IPSEC_SUPPORT and without MAC.

MFC r313805:
  Fix LINT build for powerpc.

  Build kernel modules support only when both IPSEC and TCP_SIGNATURE
  are not defined.

MFC r313922:
  For translated packets do not adjust UDP checksum if it is zero.

  In case when decrypted and decapsulated packet is an UDP datagram,
  check that its checksum is not zero before doing incremental checksum
  adjustment.

MFC r314339:
  Document that the size of AH ICV for HMAC-SHA2-NNN should be half of
  NNN bits as described in RFC4868.

  PR:		215978

MFC r314812:
  Introduce the concept of IPsec security policies scope.

  Currently are defined three scopes: global, ifnet, and pcb.
  Generic security policies that IKE daemon can add via PF_KEY interface
  or an administrator creates with setkey(8) utility have GLOBAL scope.
  Such policies can be applied by the kernel to outgoing packets and checked
  agains inbound packets after IPsec processing.
  Security policies created by if_ipsec(4) interfaces have IFNET scope.
  Such policies are applied to packets that are passed through if_ipsec(4)
  interface.
  And security policies created by application using setsockopt()
  IP_IPSEC_POLICY option have PCB scope. Such policies are applied to
  packets related to specific socket. Currently there is no way to list
  PCB policies via setkey(8) utility.

  Modify setkey(8) and libipsec(3) to be able distinguish the scope of
  security policies in the `setkey -DP` listing. Add two optional flags:
  '-t' to list only policies related to virtual *tunneling* interfaces,
  i.e. policies with IFNET scope, and '-g' to list only policies with GLOBAL
  scope. By default policies from all scopes are listed.

  To implement this PF_KEY's sadb_x_policy structure was modified.
  sadb_x_policy_reserved field is used to pass the policy scope from the
  kernel to userland. SADB_SPDDUMP message extended to support filtering
  by scope: sadb_msg_satype field is used to specify bit mask of requested
  scopes.

  For IFNET policies the sadb_x_policy_priority field of struct sadb_x_policy
  is used to pass if_ipsec's interface if_index to the userland. For GLOBAL
  policies sadb_x_policy_priority is used only to manage order of security
  policies in the SPDB. For IFNET policies it is not used, so it can be used
  to keep if_index.

  After this change the output of `setkey -DP` now looks like:
  # setkey -DPt
  0.0.0.0/0[any] 0.0.0.0/0[any] any
  	in ipsec
  	esp/tunnel/87.250.242.144-87.250.242.145/unique:145
  	spid=7 seq=3 pid=58025 scope=ifnet ifname=ipsec0
  	refcnt=1
  # setkey -DPg
  ::/0 ::/0 icmp6 135,0
  	out none
  	spid=5 seq=1 pid=872 scope=global
  	refcnt=1

  Obtained from:	Yandex LLC
  Sponsored by:	Yandex LLC
  Differential Revision:	https://reviews.freebsd.org/D9805

PR:		212018
Relnotes:	yes
Sponsored by:	Yandex LLC
2017-03-18 22:04:20 +00:00
Andrey V. Elsukov 927ecf9804 MFC r314430:
When IPv6 fragments reassembly is complete, update mbuf's csum_data
  and csum_flags using information from all fragments. This fixes
  dropping of reassembled packets due to wrong checksum when the IPv6
  checksum offloading is enabled on a network card.
2017-03-07 03:01:09 +00:00
Mark Johnston 68365e67a8 MFC r312307:
Improve some of the sysctl descriptions added in r299827.
2017-02-03 00:53:33 +00:00
Andrey V. Elsukov 2727bd1cdb MFC r309888:
Modify IPv6 statistic accounting in ip6_input().

  Add rcvif local variable to keep inbound interface pointer. Count
  ifs6_in_discard errors in all "goto bad" cases. Now it will count
  errors even if mbuf was freed. Modify all places where m->m_pkthdr.rcvif
  is used to use local rcvif variable.
2017-01-24 00:36:46 +00:00
Andrey V. Elsukov 1a6cdf5178 MFC r310258:
ip[6]_tryforward does inbound and outbound packet firewall processing.
  This can lead to change of mbuf pointer (packet filter could do m_pullup(),
  NAT, etc). Also in case of change of destination address, tryforward can
  decide that packet should be handled by local system. In this case modified
  mbuf can be returned to the ip[6]_input(). To handle this correctly, check
  M_FASTFWD_OURS flag after return from ip[6]_tryforward. And if it is present,
  update variables that depend from mbuf pointer and skip another inbound
  firewall processing.
2017-01-10 16:30:56 +00:00
Andrey V. Elsukov 042780ad1c MFC r309883:
Add ip6_tryforward() - a run to completion forwarding implementation
  for IPv6.

  It gets performance benefits from reduced number of checks. It doesn't
  copy mbuf to be able send ICMPv6 error message, because it keeps mbuf
  unchanged until the moment, when the route decision has been made.
  It doesn't do IPsec checks, and when some IPsec security policies present,
  ip6_input() uses normal slow path.

Relnotes:	yes
Sponsored by:	Yandex LLC
2017-01-08 13:31:24 +00:00
Michael Tuexen d2eb10a89c MFC r310590:
Whitespace changes.

The toolchain for processing the sources has been updated. No functional
change.
2016-12-29 11:32:42 +00:00
Michael Tuexen 634b3a9fb9 MFC r309607:
Whitespace changes.

The tools using to generate the sources has been updated and produces
different whitespaces. Commit this seperately to avoid intermixing
these with real code changes.
2016-12-18 13:00:11 +00:00
Michael Tuexen 61ddb27141 MFC r307726:
Make ICMPv6 hard error handling for TCP consistent with the ICMPv4
handling. Ensure that:
* Protocol unreachable errors are handled by indicating ECONNREFUSED
  to the TCP user for both IPv4 and IPv6. These were ignored for IPv6.
* Communication prohibited errors are handled by indicating ECONNREFUSED
  to the TCP user for both IPv4 and IPv6. These were ignored for IPv6.
* Hop Limited exceeded errors are handled by indicating EHOSTUNREACH
  to the TCP user for both IPv4 and IPv6.
  For IPv6 the TCP connected was dropped but errno wasn't set.

Sponsored by:	Netflix, Inc.
2016-12-18 12:12:49 +00:00
George V. Neville-Neil 2fbbc53016 MFC: 307541
Limit the number of mbufs that can be allocated for IPV6_2292PKTOPTIONS
(and IPV6_PKTOPTIONS).

PR:		100219
Submitted by:	Joseph Kong
2016-11-23 13:14:19 +00:00
Mark Johnston 575edc8e24 MFC r306792-r306795, r306826, r306828:
Miscellaneous ND6 code cleanups.
2016-10-19 17:23:50 +00:00
Andrey V. Elsukov cdb11f97a5 MFC r306459:
Fix bug introduced in r274300.

  In icmp6_reflect() use original source address of erroneous packet as
  destination address for source selection algorithm when original
  destination address is not one of our own.

  Reported by:	Mark Kamichoff <prox at prolixium com>
2016-10-06 08:11:53 +00:00
Mark Johnston e5bf0465af MFC r306046:
Reduce code duplication around NDP message handlers in icmp6_input().
2016-10-04 18:07:33 +00:00
Mark Johnston 3aa408de04 MFC r306285:
Rename ndpr_refcnt to ndpr_addrcnt.
2016-10-02 01:16:02 +00:00
Mike Karels 5e56c65b4b MFC r304713:
Fix L2 caching for UDP over IPv6

  ip6_output() was missing cache invalidation code analougous to
  ip_output.c. r304545 disabled L2 caching for UDP/IPv6 as a workaround.
  This change adds the missing cache invalidation code and reverts
  r304545.

  Reviewed by:    gnn
  Approved by:    gnn (mentor)
  Tested by:      peter@, Mike Andrews
  Differential Revision:  https://reviews.freebsd.org/D7591
2016-09-21 00:06:49 +00:00
Hiren Panchasara a4fa6ba837 MFC r303626 (by gallatin)
Rework IPV6 TCP path MTU discovery to match IPv4.

No objection: gallatin
2016-08-29 18:00:14 +00:00
Mike Karels 6b2a84a442 MFC r304545: Disable L2 caching for UDP over IPv6
The ip6_output routine is missing L2 cache invalication as done
in ip_output.  Even with that code, some problems with UDP over
IPv6 have been reported.  Diabling L2 cache for that problem works
around the problem for now.

PR:		211872 211926
Reviewed by:	gnn
Approved by:	gnn (mentor)
Tested by:	peter@, Mike Andrews
MFC after:	immediate
2016-08-20 20:56:36 +00:00
Andrey V. Elsukov 1ba8848f30 MFC r302906:
Add net.inet6.ip6.intr_queue_maxlen sysctl. It can be used to
  change netisr queue limit for IPv6 at runtime.
2016-08-14 20:22:03 +00:00
Andrey V. Elsukov e08ff22972 MFC r303657:
Fix NULL pointer dereference.
  ro pointer can be NULL when IPSec consumes mbuf.

  PR:		211486
Approved by:	re (gjb)
2016-08-05 15:12:29 +00:00
Mike Karels 89a705c439 MFC r303171: Fix per-connection L2 caching in fast path
r301217 re-added per-connection L2 caching from a previous change,
but it omitted caching in the fast path.  Add it.

Reviewed By: gallatin
Approved by: gnn (mentor)
Approved by: re (kostikbel)
Differential Revision: https://reviews.freebsd.org/D7239
2016-08-03 06:32:44 +00:00
Dimitry Andric 3872d54617 MFC r302784:
Fix a page fault in ip6_setpktopt(), occurring when the pflog module is
loaded, and syncthing is started, which uses setsockopt(IPV6_PKGINFO).

This is because pflog interfaces do not normally have an IPv6 address,
causing the ND_IFINFO() macro to dereference a NULL pointer.

Approved by:	re (kib)
Reviewed by:	ae
PR:		210943
2016-07-16 10:50:28 +00:00
Michael Tuexen 55b8cd93ef Don't consider the socket when processing an incoming ICMP/ICMP6 packet,
which was triggered by an SCTP packet. Whether a socket exists, is just
not relevant.

Approved by: re (kib)
MFC after: 1 week
2016-06-23 09:13:15 +00:00
Andrey V. Elsukov a844d49cc6 Fix the NULL pointer dereference for unresolved link layer entries in
the netinet6 code. Copy link layer address only when corresponding entry
has LLE_VALID flag.

PR:		210379
Approved by:	re (kib)
2016-06-22 11:29:21 +00:00
Bjoern A. Zeeb 89856f7e2d Get closer to a VIMAGE network stack teardown from top to bottom rather
than removing the network interfaces first. This change is rather larger
and convoluted as the ordering requirements cannot be separated.

Move the pfil(9) framework to SI_SUB_PROTO_PFIL, move Firewalls and
related modules to their own SI_SUB_PROTO_FIREWALL.
Move initialization of "physical" interfaces to SI_SUB_DRIVERS,
move virtual (cloned) interfaces to SI_SUB_PSEUDO.
Move Multicast to SI_SUB_PROTO_MC.

Re-work parts of multicast initialisation and teardown, not taking the
huge amount of memory into account if used as a module yet.

For interface teardown we try to do as many of them as we can on
SI_SUB_INIT_IF, but for some this makes no sense, e.g., when tunnelling
over a higher layer protocol such as IP. In that case the interface
has to go along (or before) the higher layer protocol is shutdown.

Kernel hhooks need to go last on teardown as they may be used at various
higher layers and we cannot remove them before we cleaned up the higher
layers.

For interface teardown there are multiple paths:
(a) a cloned interface is destroyed (inside a VIMAGE or in the base system),
(b) any interface is moved from a virtual network stack to a different
network stack ("vmove"), or (c) a virtual network stack is being shut down.
All code paths go through if_detach_internal() where we, depending on the
vmove flag or the vnet state, make a decision on how much to shut down;
in case we are destroying a VNET the individual protocol layers will
cleanup their own parts thus we cannot do so again for each interface as
we end up with, e.g., double-frees, destroying locks twice or acquiring
already destroyed locks.
When calling into protocol cleanups we equally have to tell them
whether they need to detach upper layer protocols ("ulp") or not
(e.g., in6_ifdetach()).

Provide or enahnce helper functions to do proper cleanup at a protocol
rather than at an interface level.

Approved by:		re (hrs)
Obtained from:		projects/vnet
Reviewed by:		gnn, jhb
Sponsored by:		The FreeBSD Foundation
MFC after:		2 weeks
Differential Revision:	https://reviews.freebsd.org/D6747
2016-06-21 13:48:49 +00:00
Pedro F. Giffuni 268aab1cfc Remove the SIOCSIFALIFETIME_IN6 ioctl.
The SIOCSIFALIFETIME_IN6 provided by the kame project is unused,
it can't really be used safely and has been completely removed from
NetBSD and OpenBSD.

Obtained from:	NetBSD (kern/35897)
PR:		210148 (exp-run)
Reviewed by:	ae, hrs
Relnotes:	yes
Approved by:	re (glebius)
Differential Revision:	https://reviews.freebsd.org/D5491
2016-06-13 22:31:16 +00:00
Andrey V. Elsukov 4c10540274 Cleanup unneded include "opt_ipfw.h".
It was used for conditional build IPFIREWALL_FORWARD support.
But IPFIREWALL_FORWARD option was removed a long time ago.
2016-06-09 05:48:34 +00:00
Bjoern A. Zeeb 74b44794c6 Make KASSERT message more useful by printing the variables on which
we assert.

Obtained from:	projects/vnet
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
2016-06-06 22:34:12 +00:00
Bjoern A. Zeeb 99a0c4062d Move the callout_reset() to the end of the work not having it stick
before we do anything.

Obtained from:	projects/vnet
MFC after:	2 week
Sponsored by:	The FreeBSD Foundation
2016-06-06 14:01:09 +00:00
Bjoern A. Zeeb 484149def8 Introduce a per-VNET flag to enable/disable netisr prcessing on that VNET.
Add accessor functions to toggle the state per VNET.
The base system (vnet0) will always enable itself with the normal
registration. We will share the registered protocol handlers in all
VNETs minimising duplication and management.
Upon disabling netisr processing for a VNET drain the netisr queue from
packets for that VNET.

Update netisr consumers to (de)register on a per-VNET start/teardown using
VNET_SYS(UN)INIT functionality.

The change should be transparent for non-VIMAGE kernels.

Reviewed by:	gnn (, hiren)
Obtained from:	projects/vnet
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D6691
2016-06-03 13:57:10 +00:00
George V. Neville-Neil 6d76822688 This change re-adds L2 caching for TCP and UDP, as originally added in D4306
but removed due to other changes in the system. Restore the llentry pointer
to the "struct route", and use it to cache the L2 lookup (ARP or ND6) as
appropriate.

Submitted by:	Mike Karels
Differential Revision:	https://reviews.freebsd.org/D6262
2016-06-02 17:51:29 +00:00
Mark Johnston 1b28988b44 Exploit r301213 to fix in6 ifaddr locking in pfxlist_onlink_check().
Reviewed by:	ae, hrs
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D6639
2016-06-02 17:21:57 +00:00
Mark Johnston 0973ca723c Always start IPv6 DAD asynchronously.
Otherwise we transmit the first neighbour solicitation in the context of the
caller of nd6_dad_start(), which can easily result in lock recursion. When
DAD is to be started after some delay, we send the first NS from the DAD
callout handler, so just change the implementation to do this in the
non-delayed case as well.

Reviewed by:	ae, hrs
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D6639
2016-06-02 17:17:15 +00:00
Bjoern A. Zeeb 3f58662dd9 The pr_destroy field does not allow us to run the teardown code in a
specific order.  VNET_SYSUNINITs however are doing exactly that.
Thus remove the VIMAGE conditional field from the domain(9) protosw
structure and replace it with VNET_SYSUNINITs.
This also allows us to change some order and to make the teardown functions
file local static.
Also convert divert(4) as it uses the same mechanism ip(4) and ip6(4) use
internally.

Slightly reshuffle the SI_SUB_* fields in kernel.h and add a new ones, e.g.,
for pfil consumers (firewalls), partially for this commit and for others
to come.

Reviewed by:		gnn, tuexen (sctp), jhb (kernel.h)
Obtained from:		projects/vnet
MFC after:		2 weeks
X-MFC:			do not remove pr_destroy
Sponsored by:		The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D6652
2016-06-01 10:14:04 +00:00
Michael Tuexen 3d48d25be7 Add PR_CONNREQUIRED for SOCK_STREAM sockets using SCTP.
This is required to signal connetion setup on non-blocking sockets
via becoming writable. This still allows for implicit connection
setup.

MFC after:	1 week
2016-05-30 18:24:23 +00:00
Gleb Smirnoff 6351b3857b Plug route reference underleak that happens with FLOWTABLE after r297225.
Submitted by:	Mike Karels <mike karels.net>
2016-05-27 17:31:02 +00:00
Mark Johnston 65fdf52123 Mark the prefix and default router list sysctl handlers MPSAFE.
MFC after:	2 weeks
2016-05-23 20:18:11 +00:00
Mark Johnston cc51be7b81 Acquire the nd6 lock in the prefix list sysctl handler.
The nd6 lock will be used to synchronize access to the NDP prefix list.

MFC after:	2 weeks
Tested by:	Jason Wolfe (as part of a larger change)
2016-05-23 20:15:08 +00:00