Commit Graph

320 Commits

Author SHA1 Message Date
christos e5e40d965d Add IP_BINDANY, IPV6_BINDANY which can be used to bind to any address in
order to implement transparent proxies.
2020-09-08 14:12:57 +00:00
christos a7b8699571 Don't cache the sa, because we are dealing with multiple mbufs (from ozaki-r) 2020-08-28 17:01:48 +00:00
ozaki-r d511e529cc inet: reduce silent packet discards 2020-08-28 06:31:42 +00:00
ozaki-r 25b1ccbabd inet: reduce indents of a normal path to improve readability (NFCI) 2020-08-28 06:22:25 +00:00
ozaki-r c1e00d7df1 inet, inet6: count packets dropped by IPsec
The counters count packets dropped due to security policy checks.
2020-08-28 06:19:13 +00:00
msaitoh 53636c3c61 s/referece/reference/ in comment. 2019-12-27 10:17:56 +00:00
knakahara 3b6248225f The packets which will be esp-fragmented should not be applied pfil. Pointed out by ohishi@IIJ, thanks. 2019-06-05 01:31:04 +00:00
knakahara 4cdefa22a1 Fix rtcache cannot be released once an esp-fragmented packet is sent. Pointed out by ohishi@IIJ, thanks. 2019-06-05 01:27:20 +00:00
ozaki-r 6c6d1e4f71 Get rid of IFNET_LOCK for if_mcast_op to avoid a deadlock
The IFNET_LOCK was added to avoid data races on if_flags for IFF_ALLMULTI.
Unfortunatetly it caused a deadlock instead.  A known scenario causing a
deadlock is to occur the following two operations concurrently: (a) a removal of
an IP adddres assigned to an interface and (b) a manipulation of multicast
groups to the interface.  The resource dependency graph is like this:
  softnet_lock => IFNET_LOCK => psref_target_destroy => softint => softnet_lock

Thanks to the previous commit that avoids data races on if_flags for
IFF_ALLMULTI by another approach, we can remove IFNET_LOCK and defuse the
deadlock.

PR kern/54189
2019-05-15 02:59:18 +00:00
ozaki-r 6d8eb4f9d2 Count packets dropped by pfil 2019-05-13 07:47:59 +00:00
mrg 3035d148fb rework the #ifdef IPSEC code to not use fallthru.
same number of lines with more local context.
2019-02-04 10:48:46 +00:00
maxv b1305a6d63 Replace: M_MOVE_PKTHDR -> m_move_pkthdr. No functional change, since the
former is a macro to the latter.
2018-12-22 13:11:37 +00:00
rin 7f120f6563 Simplify logic in ip{,6}_output().
Now, we have M_CSUM_TSOv[46] bit in ifp->if_csum_flags_tx when
TSO[46] is enabled for the interface. So we can simply check
whether TSO[46] is required in a packet but missing in the
interface by (sw_csum & M_CSUM_TSOv[46]).

Note that this is a very rare case where TSO[46] is suddenly
turned off during a packet passing b/w TCP and IP.

part of PR kern/53562
OK msaitoh
2018-12-12 01:53:52 +00:00
maxv 3574e9908d Rename
ip_undefer_csum  -> in_undefer_cksum
	in_delayed_cksum -> in_undefer_cksum_tcpudp

The two previous names were inconsistent and misleading.

Put the two functions into in_offload.c. Add comments to explain what
we're doing.

The same could be done for IPv6.
2018-07-11 05:25:45 +00:00
maxv 975c668a99 Copy more mbuf flags. 2018-06-02 11:56:57 +00:00
maxv 14fc7e2d6a Fix an XXX of mine, be clearer about what we're doing. Basically we want to
preserve the fragment offset and flags. That's necessary if the packet
we're fragmenting is itself a fragment.
2018-05-29 17:21:57 +00:00
maxv d920327205 Remove unused and misleading argument from ipsec_set_policy. 2018-04-29 11:51:08 +00:00
maxv 2b3801633e Remove #ifndef __vax__.
The check enforces a 4-byte-aligned size for the option mbuf. If the size
is not multiple of 4, the computation of ip_hl gets truncated in the
output path. There is no reason for this check not to be present on VAX.

While here add a KASSERT in ip_insertoptions to enforce the assumption.

Discussed briefly on tech-net@
2018-04-21 13:22:06 +00:00
maxv c592a19e59 Remove useless comment and style. 2018-04-13 09:00:29 +00:00
maxv b5d40d5d71 Reduce the diff between similar blocks. 2018-04-13 08:47:46 +00:00
maxv 6d38166bdc Reorder a few instructions to clarify. Replace two bcopy by memcpy. 2018-04-13 08:12:51 +00:00
maya 54d22fc1d3 correct typo: and and -> and (comments only)
heads up on this being a common typo from chris28.
2018-03-30 22:54:36 +00:00
maxv 6c5d24ed60 Add KASSERTs, we don't want m_nextpkt in ipsec{4/6}_process_packet. 2018-03-03 09:39:29 +00:00
maxv faad9849ec Dedup: merge ipsec4_set_policy and ipsec6_set_policy. The content of the
original ipsec_set_policy function is inlined into the new one.
2018-02-27 15:01:30 +00:00
maxv 580ac4be42 Dedup: merge
ipsec4_get_policy and ipsec6_get_policy
	ipsec4_delete_pcbpolicy and ipsec6_delete_pcbpolicy

The already-existing ipsec_get_policy() function is inlined in the new
one.
2018-02-27 14:44:10 +00:00
christos c98f924910 Keep a pointer to the interface of the multicast membership, because the
multicast element itself might go away in in_delmulti (but the interface
can't because we hold the lock). From ozaki-r@
2018-02-12 18:19:12 +00:00
mrg 1f562f07aa ip_add_membership() has an missing {} issue, but solve it by
dropping the "goto out" that would have happened immediately
next anyway, ie, should be NFC.
2018-02-07 06:21:23 +00:00
maxv ca56b5b05a Several changes, mostly cosmetic:
* Add a KASSERT in ip_output(), we expect (at least) the IP header to be
   here.

 * In ip_fragment(), declare two variables instead of recomputing the
   values each time. Add an XXX for ipoff, it seems to me we should also
   remove IP_RF.

 * Rename the arguments of ip_optcopy().

 * Style: use NULL for pointers, remove ()s for return statements, and
   add whitespaces for clarity.

No real functional change.
2018-02-06 17:08:18 +00:00
christos fc005591f5 from ozaki-r: use the proper ifp.
XXX: perhaps push the lock in in_delmulti()?
2018-01-10 18:51:31 +00:00
christos dcbd947bf6 - this is not python, we need braces
- protect ifp locking against NULL
2018-01-10 17:36:06 +00:00
christos f7805b6647 Remove comment now that the getsockopt code passes the size. 2018-01-01 16:14:30 +00:00
christos 645664bc7b 1) "#define ipi_spec_dst ipi_addr" in <netinet/in.h>
2) Change the IP_RECVPKTINFO option to control the generation of
   IP_PKTINFO control messages, the way it's done in Solaris.
3) Remove the superfluous IP_RECVPKTINFO control message.
4) Change the IP_PKTINFO option to do different things depending on
   the parameter it's supplied with:
   - If it's sizeof(int), assume it's being used as in Linux:
     - If it's non-zero, turn on the IP_RECVPKTINFO option.
     - If it's zero, turn off the IP_RECVPKTINFO option.
   - If it's sizeof(struct in_pktinfo), assume it's being used as in
     Solaris, to set a default for the source interface and/or
     source address for outgoing packets on the socket.
5) Return what Linux or Solaris compatible code expects, depending
   on data size, and just added a fallback to a Linux (and current NetBSD)
   compatible value if the size is unknown (as it is now), or,
   in the future, if the calling application specifies a receiving
   buffer that doesn't match either data item.

From: Tom Ivar Helbekkmo
2018-01-01 00:51:36 +00:00
ozaki-r df9fd3e60f Fix usage of curlwp_bind in ip_output
curlwp_bindx must be called in LIFO order, i.e., we can't call curlwp_bind
and curlwp_bindx like this:
  bound1 = curlwp_bind();
  bound2 = curlwp_bind();
  curlwp_bindx(bound1);
  curlwp_bindx(bound2);

ip_outout did so if NET_MPSAFE. Fix it.
2017-12-22 11:22:37 +00:00
ozaki-r bde7231efb Ensure to call if_mcast_op with holding IFNET_LOCK
Note that CARP doesn't deal with IFNET_LOCK yet.
2017-12-15 04:03:46 +00:00
ryo c2f85cb6e9 As is the case with IPV6_PKTINFO, IP_PKTINFO can be sent without EADDRINUSE
even if the UDP address:port in use is specified.
2017-12-11 05:47:18 +00:00
ozaki-r cead3b8854 Provide macros for softnet_lock and KERNEL_LOCK hiding NET_MPSAFE switch
It reduces C&P codes such as "#ifndef NET_MPSAFE KERNEL_LOCK(1, NULL); ..."
scattered all over the source code and makes it easy to identify remaining
KERNEL_LOCK and/or softnet_lock that are held even if NET_MPSAFE.

No functional change
2017-11-17 07:37:12 +00:00
ryo 1581658c21 Add support IP_PKTINFO for sendmsg(2).
The source address or output interface can be specified by adding IP_PKTINFO
to the control part of the message on a SOCK_DGRAM or SOCK_RAW socket.

Reviewed by ozaki-r@ and christos@. thanks.
2017-08-10 04:31:58 +00:00
para e3902ee896 kmem_intr_free kmem_intr_[z]alloced memory
the underlying pools are the same but api-wise those should match
2017-07-23 10:55:00 +00:00
roy 51158c7f10 Rename u to udst, .dst to .sa and .dst4 to sin.
Create sockaddr for the source address in usrc so it won't stamp on udst.

This fixes a regression caused in r1.280
2017-07-04 10:25:45 +00:00
khorben 774ab82e9f Typo 2017-07-03 18:54:11 +00:00
roy c02f483da3 When outputting, search for the sending address on the sending interface
rather than blindly picking the first matcing address from any interface
when testing source address validity.

This allows another interface to have the same address, but be detached.
2017-07-03 16:43:01 +00:00
ryo 13f80cd683 replace in_fmtaddr() by IN_PRINT(), and delete function in_fmtaddr() 2017-05-12 17:53:53 +00:00
ozaki-r 38eefa3747 Stop ipsec4_output returning SP to the caller
SP isn't used by the caller (ip_output) and also holding its
reference looks unnecessary.
2017-05-10 09:34:51 +00:00
christos 57b897e7c9 PR/52074: Frank Kardel: current npf map directive broken
Don't filter packets that can't be resolved to source interfaces because
they could have been generated by a packet filter.
2017-05-07 16:41:22 +00:00
ozaki-r 89bba5e4dd Fix the position of curlwp_bindx; it should be after if_put 2017-03-05 11:07:46 +00:00
ozaki-r 2495e7a0c7 Pass inpcb/in6pcb instead of socket to ip_output/ip6_output
- Passing a socket to Layer 3 is layer violation and even unnecessary
- The change makes codes of callers and IPsec a bit simple
2017-03-03 07:13:06 +00:00
ozaki-r d0c11d0872 Make sure imo_membership is protected by inp's lock (solock) 2017-03-02 05:29:31 +00:00
ozaki-r 36ae5d22b0 Make usages of ifp MP-safe in some functions of IP multicast 2017-03-02 05:24:23 +00:00
ozaki-r 559b831490 Add assertions and comments for lock states of socket and pcb 2017-02-22 07:05:04 +00:00
ozaki-r 77a7c1c676 Make NOMPSAFE comments informative 2017-02-17 04:31:34 +00:00