Commit Graph

4249 Commits

Author SHA1 Message Date
rin 5b839bef49 Align function name in its declaration consistently.
No binary changes.
2023-06-16 02:48:07 +00:00
rin c8c6b0abb0 Consistently use __inline instead of inline, as done for rev. 1.119:
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/net/route.h#rev1.119
2023-06-16 02:46:23 +00:00
ozaki-r 174092f275 route: run workqueue kthreads with KERNEL_LOCK unless NET_MPSAFE
Without KERNEL_LOCK, rt_timer_work and rt_free_work can run in parallel
with other LWPs running in the network stack, which eventually results
in say use-after-free of a deleted route.
2023-06-05 03:51:45 +00:00
andvar d7488b2d05 s/explcit/explicit/ in comment. 2023-05-28 08:09:34 +00:00
jakllsch c54128fc11 Give scope and additional details to wg(4) diagnostic messages. 2023-04-11 14:03:46 +00:00
andvar 45758f9ad4 s/termintaed/terminated/ in comment. 2023-04-05 19:56:27 +00:00
andvar 95f94af301 fix various typos in documentation, comments and sysctl device description.
mainly aion -> ation and inlude -> include.
2023-03-26 19:10:32 +00:00
andvar 5583e1ee44 s/deteted/detected/ in log message. 2023-03-25 21:35:49 +00:00
riastradh 5e72ca9101 npf: Eliminate __HAVE_ATOMIC_AS_MEMBAR conditionals.
Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2023/02/23/msg028729.html

Requested by rmind@:
https://github.com/rmind/npf/pull/127#issuecomment-1399573125
2023-02-24 11:03:01 +00:00
riastradh fa8628f4ec sys/net/if.c: Eliminate __HAVE_ATOMIC_AS_MEMBAR conditionals.
Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2023/02/23/msg028729.html
2023-02-24 11:02:45 +00:00
kardel 1165567d46 PR kern/56052:
allow block-return packets passed through without rule matching.
Included up-stream as https://github.com/rmind/npf/pull/115
2023-02-12 13:38:37 +00:00
kardel 57cb3743d4 PR kern/55654:
Switch default for parameter npf ip4.reassembly to 1.
This makes the NPF default configuration comply with host
requirements for IPv4.
2023-02-12 13:21:28 +00:00
gutteridge bb48f2ad77 bpf.c: support loopback writes when BIOCSHDRCMPLT is set
Following changes in r. 1.249 "bpf: support sending packets on loopback
interfaces", also allow for this to succeed when the "header complete"
flag is set, which is the practice of some tools, e.g., tcpreplay and
Scapy. With this change, both of those example tools now work, e.g.,
Scapy passes "L3bpfSocket - send and sniff on loopback" in its test
suite.

There are several ways of addressing this issue; this commit is
intended to be the most conservative and consistent with the previous
changes. (E.g., FreeBSD instead has special handling of this condition
in its if_loop.c.)
2023-02-08 01:37:53 +00:00
gutteridge 1b7584da6c bpf.c: fix a few typos and grammatical issues in comments 2023-02-07 01:46:37 +00:00
riastradh 2f9d5bcd6c npf(9): Drop table lock around copyout.
It is forbidden to hold a spin lock around copyout, and t_lock is a
spin lock.

We need t_lock in order to iterate over the list of entries.
However, during copyout itself, we only need to ensure that the
object we're copying out isn't freed by npf_table_remove or
npf_table_gc.

Fortunately, the only caller of npf_table_list, npf_table_remove, and
npf_table_gc is npfctl_table, and it serializes all of them by the
npf config lock.  So we can safely drop t_lock across copyout.

PR kern/57136
PR kern/57181
2023-01-23 13:40:04 +00:00
riastradh 976285b5e8 npf(9): Another comment tweak to match upstream.
No functional change.
2023-01-22 18:45:43 +00:00
riastradh edfe75c0f8 npf(9): Update comment to reduce diff from upstream.
No functional change.
2023-01-22 18:39:35 +00:00
riastradh 75fac99873 npf(9): Use __HAVE_ATOMIC_AS_MEMBAR around refcnt consistently. 2023-01-22 18:39:22 +00:00
ozaki-r 9e45e086e6 tap: link up an interface cloned from /dev/tap
Fix PR 57155 (partially)
2023-01-06 01:54:22 +00:00
christos bcf4524658 centralize the kauth ugliness. 2023-01-05 20:32:18 +00:00
jakllsch 920a56487e wg(4): Allow non-root to retrieve information other than the private
key and the peer preshared key.

Add kauth(9) enums for wg(4) and add use them in suser secmodel.

Refines fix for PR 57161.
2023-01-05 18:29:45 +00:00
jakllsch b820662b29 Check for authorization for SIOCSDRVSPEC and SIOCGDRVSPEC ioctls for wg(4).
Addresses PR 57161.
2023-01-05 02:38:51 +00:00
knakahara 097861d9a7 Fix libreswan build failure. Pointed out by Andrew Cagney, thanks. 2023-01-04 01:58:33 +00:00
riastradh e2736fa3cf route(4): Work around deadlock in rt_free wait path.
PR kern/56844

XXX pullup-8
XXX pullup-9
XXX pullup-10
2022-12-22 13:54:57 +00:00
chs 238664abb5 ppp: remove ioctls that never worked and crash the kernel
Remove vestigial bits of PPP HDLC support that never worked on netbsd.
The TIOCRCVFRAME ioctl was apparently intended to be called only from
within the kernel, but nothing prevents user code from calling this ioctl
and crashing the kernel.

Reported-by: syzbot+53e4620d0d17a4dd08fa@syzkaller.appspotmail.com
Reported-by: syzbot+d3a8b784fed1e32e0768@syzkaller.appspotmail.com
Reported-by: syzbot+375bab63345a6a7a3331@syzkaller.appspotmail.com
Reported-by: syzbot+ba7ac85196274a20b54a@syzkaller.appspotmail.com
Reported-by: syzbot+57ddb63a3d1d3299ef18@syzkaller.appspotmail.com
2022-12-21 19:08:22 +00:00
ozaki-r 39ce7d7534 bpf: support sending packets on loopback interfaces
Previously sending packets on a loopback interface via bpf failed
because the packets are treated as AF_UNSPEC by bpf and the loopback
interface couldn't handle such packets.

This fix enables user programs to prepend a protocol family (AF_INET or
AF_INET6) to a payload.  bpf interprets it and treats a packet as so,
not just AF_UNSPEC.  The protocol family is encoded as 4 bytes, host byte
order as per DLT_NULL in the specification(*).

(*) https://www.tcpdump.org/linktypes.html

Proposed on tech-net and tech-kern
2022-11-30 06:02:37 +00:00
knakahara 7cb557b6cc Support explicit unnumbered interface.
Currently, NetBSD supports implicit unnumbered interface by setting
the same IP address to two interfaces.  However, such interface is not
treated as unnumbered when one of the interfaces is being changed and
has been changed IP address.  That behavior can be harmful for some
routing daemons.
2022-11-25 08:39:32 +00:00
msaitoh 5294306f07 KNF. No functional change. 2022-11-25 06:18:42 +00:00
yamt d26dce9ea2 bpf: refresh bd_pid in a few more places as well
This made "netstat -B" show hostapd and wpa_supplicant for me.

kingcrab# netstat -B
Active BPF peers
PID     Int     Recv     Drop     Capt     Flags  Bufsize  Comm
433     urtwn0  102      0        2        I-RSH  524288   hostapd
211     urtwn0  102      0        4        I-RS-  32768    dhcpd
670     bwfm0   295      0        2        I-RSH  524288   wpa_supplicant
kingcrab#
2022-11-19 08:53:06 +00:00
yamt 34172d955e Make arp have its own mowner
This helped me to debug mbuf leaks in arp.
(if_arp.c rev. 1.298)
2022-11-19 08:00:51 +00:00
roy d66a17fc6d arp: Validate ARP source hardware address matches Ethernet source
RFC 5227 section 1.1 states that for a DaD ARP probe the sender hardware
address must match the hardware address of the interface sending the
packet.

We can now verify this by checking the mbuf tag PACKET_TAG_ETHERNET_SRC.

This fixes an obsure issue where an old router was sending out bogus
ARP probes.

Thanks to Ryo Shimizu <ryo@nerv.org> for the re-implementation.
2022-11-15 10:47:39 +00:00
roy 7f8cc08460 Revert prior. 2022-11-15 09:13:43 +00:00
roy 17a43b3883 net: Store a pointer to the Layer 2 Sender Hardware address in mbuf
The BSD networking stack is designed around passing a mbuf down the chain
and each layer removes the part it's interested in before passing it to
the next. This makes it easy for each layer to do it's work,
but non trivial to work backwards.

As such we now store a pointer to the Senders Hardware address in the
mbuf packet header so that protocols can perform any required validation.
2022-11-14 09:23:42 +00:00
msaitoh a3d9e0f54e Increase sdl_data so that more then IFNAMSIZ bytes are available (again).
COMPAT_9 is not required.

 - The getifaddrs(3) function has no problem. The routing message has no
   problem because struct rtm_msglen has rtm_msglen and we can get the next
   message using with it. There is no any kernel data structure which has
   struct sockaddr_dl foobadr[xxx] array.

 - A data passed from userland and a kernel data are compared with
   sockaddr_cmp(). The return value is used to check if the size is
   inadequate or not.

 - In the kernel, sdl_len is not directly used for the length of memcpy()
   but the sockaddr_dl_measure() is used for it.
2022-11-07 08:32:35 +00:00
ozaki-r 2ba9f052f6 inpcb: rename functions to inpcb_*
Inspired by rmind-smpnet patches.
2022-11-04 09:00:58 +00:00
ozaki-r f8c27a68f7 Adjust pf, wg, dccp and sctp for struct inpcb integration 2022-10-28 05:20:08 +00:00
msaitoh 124a11c27c Revert if_dl.h change. It'll be commited with the COMPAT_9 code in future. 2022-10-27 00:25:11 +00:00
riastradh 0af1a55eb9 ppp(4): Convert to ttylock/ttyunlock. 2022-10-26 23:42:56 +00:00
riastradh ed89fc3278 sl(4): Convert to ttylock/ttyunlock. 2022-10-26 23:42:42 +00:00
msaitoh 926e2913c5 Make ifq_drops in struct ifqueue and struct ifaltq 64 bit. 2022-10-24 08:11:24 +00:00
msaitoh d130a40a15 Increase sdl_data so that more then IFNAMSIZ bytes are available.
- Increase the size of dl_data[] from 12 to 24.
 - Same as OpenBSD.
2022-10-24 07:45:44 +00:00
knakahara 13ced16cf4 Add sadb_x_policy_flags to inform SP origination.
This extension(struct sadb_x_policy) is *not* defined by RFC2367.

OpenBSD does not have reserved fields in struct sadb_x_policy.
Linux does not use this field yet.
FreeBSD uses this field as "sadb_x_policy_scope"; the value range is
from 0x00 to 0x04.

We use from most significant bit to avoid the above usage.
2022-10-11 09:51:47 +00:00
knakahara 814970e5a5 Fix overflow case detected by clang. Pointed out by wsh@IIJ, thanks. 2022-10-06 06:59:24 +00:00
msaitoh 9bfc1ad8f0 Fix comment (!COMPAT_RTSOCK case). No functional change. 2022-10-04 07:06:31 +00:00
knakahara 31414b24f7 ipsecif(4) can use fixed SP reqid based on ifindex, that can reduce number of reqid.
If we want to use fixed SP reqid for ipsecif(4), set
net.ipsecif.use_fixed_reqid=1  Default(=0) is the same as before.
net.ipsecif.use_fixed_reqid can be changed only if there is no ipsecif(4) yet.

If we want to change the range of ipseif(4) SP reqid,
set net.ipsecif.reqid_base and net.ipsecif.reqid_last.
These can also be changed only if there is no ipsecif(4) yet.
2022-09-30 07:36:36 +00:00
knakahara bf4e44ab86 Remove routes on an address removal if the routes referencing to the address. Implemented by ozaki-r@n.o.
A route that has a gateway is on a connected route can be invalid if the
connected route is deleted, i.e., an associated address is removed.
Traditionally NetBSD doesn't sweep such a route on the address removal.  Sending
packets over the route fails with "No route to host".  Also the route holds an
orphan ifaddr as rt_ifa that is destructed say by in_purgeaddr.

If the same address is assgined again in such a state, there can be two
different ifaddr objects with the same address.  Until recently it's not a
big problem because we can send packets anyway.  However after MP-ification
of the network stack, we can't send packets because we strictly check if rt_ifa
(i.e., the (old) ifaddr) is valid.

This change automatically removes such routes on a removal of an associated
address to avoid keeping inconsistent routes.
2022-09-20 02:23:37 +00:00
thorpej 68397fb96d Eliminate use of IFF_OACTIVE. 2022-09-18 19:24:14 +00:00
martin 9ac2e5d1c0 Typo in comment 2022-09-18 16:58:54 +00:00
thorpej 2b30b85b73 Fix "MPLS handled this" detection logic in the rump environment. 2022-09-04 23:34:51 +00:00
thorpej 06a0da98f2 In pktq_flush():
- Run a dummy softint at IPL_SOFTNET on all CPUs to ensure that the
  ISR for this pktqueue is not running (addresses a pre-existing XXX).
- Hold the barrier lock around the critical section to ensure that
  implicit pktq_barrier() calls via pktq_ifdetach() are held off during
  the critical section.
- Ensure the critical section completes in minimal time by not freeing
  memory during the critical section; instead, just build a list of the
  packets pulled out of the per-CPU queues and free them after the critical
  section is over.
2022-09-04 17:34:43 +00:00