summaryrefslogtreecommitdiff
path: root/sys/netinet6/in6.c
AgeCommit message (Collapse)Author
2023-06-28use refcnt API for multicast addresses, add tracepoint:refcnt:ifmaddr probeKlemens Nanni
Replace hand-rolled reference counting with refcnt_init(9) and hook it up with a new dt(4) probe. OK bluhm mvs
2023-04-21Drop error variable and return directly; OK mvs tbKlemens Nanni
2023-04-19move kernel lock into multicast ioctl handlers; OK mvsKlemens Nanni
2022-12-06Add missing kernel lock around (*if_ioctl)() call withinVitaliy Makkoveev
in{,6}_addmulti(). Since kernel lock is no more taken while following setsockopt() path, it should be taken in this place. Corresponding in{,6}_delmulti() already acquire kernel lock around (*if_ioctl)(). Problem reported and diff tested by weerd@ ok kn@ bluhm@
2022-12-02Unlock in6_ioctl_get() aka. SIOCGIF{DSTADDR,NETMASK,AFLAG,ALIFETIME}_IN6Klemens Nanni
First the right address is picked from the net lock protected if_addrlist. Then all ioctls just copy out the address, nothing requires the kernel lock. SIOCGIFDSTADDR_IN6 checks the net lock protected if_flags, SIOCGIFALIFETIME_IN6 computes lifetimes which only need the address. This removes the last kernel lock from IPv6 read ioctls (multicast being the untouched exception here). Users of these ioctl(2)s are route6d(8), rad(8), slaacd(8), isakmpd(8) and of course ifconfig(8). OK mvs
2022-11-30Unlock nd6_ioctl(), push kernel lock into in6_ioctl_{get,change_ifaddr}()Klemens Nanni
Neighbour Discovery information is protected by the net lock, as documented in nd6.h struct nd_ifinfo. ndp(8) is the only SIOCGIFINFO_IN6 and SIOCGNBRINFO_IN6 user in base. nd6_lookup(), also used in ICMP6 input and IPv6 forwarding, only needs the net lock. OK mvs
2022-11-23Add *if_nd to struct ifnet, call nd6_if{at,de}tach() directlyKlemens Nanni
*if_afdata[] and struct domain's dom_if{at,de}tach() are only used with IPv6 Neighbour Discovery in6_dom{at,de}tach(), which allocate/init and free single struct nd_ifinfo. Set up a new ND-specific *if_nd member directly to avoid yet another layer of indirection and thus make the generic domain API obsolete. The per-interface data is only accessed in nd6.c and nd6_nbr.c through the ND_IFINFO() macro; it is allocated and freed exactly once during interface at/detach, so document it as [I]mmutable. OK bluhm mvs claudio
2022-11-23Recommit previous "Remove useless struct in6_ifextra"Klemens Nanni
This was the right diff after all, I just confused myself between trees. OK bluhm --- Remove useless struct in6_ifextra in6_var.h r1.75 removed all other struct members. Now It only contains a single struct nd_ifinfo pointer, so address family specific data might as well be just that. ND_IFINFO() is the only way nd6_nbr.c and nd6.c access this data, there is no other usage of if_afdata[]. One allocation and unhelpful indirection less per interface. All under _KERNEL. OK claudio
2022-11-22Backout "Remove useless struct in6_ifextra" commitKlemens Nanni
I committed the wrong iteration of this diff, sorry for the noise.
2022-11-22Use local variable consistentlyKlemens Nanni
All prior lines in this function already use it, do so on the last one. OK claudio
2022-11-22Remove useless struct in6_ifextraKlemens Nanni
in6_var.h r1.75 removed all other struct members. Now It only contains a single struct nd_ifinfo pointer, so address family specific data might as well be just that. ND_IFINFO() is the only way nd6_nbr.c and nd6.c access this data, there is no other usage of if_afdata[]. One allocation and unhelpful indirection less per interface. All under _KERNEL. OK claudio
2022-11-19Push kernel lock into pru_control() aka. in6_control() / in_control()Klemens Nanni
so->so_state is already read without kernel lock inside soo_ioctl() which calls pru_control() aka in6_control() and in_control(). OK mvs
2022-11-12Remove unused fields from struct in6_ifextraKlemens Nanni
This is all under _KERNEL: - rs_lhcookie was added in 2014 110585f259f4974284e531f0a1e121b001a580dc "Move sending of router solicitations to the kernel; [...]" but never used - nprefixes and ndefrouters became obsolete with 2017 4a2f474d14c160dc7829cce0149ead09d473ece9 "Remove sending of router solicitations and processing of router advertisements from the kernel. [...]" OK mpi
2022-09-08Rename global ifnet TAILQKlemens Nanni
Naming the list like the struct itself makes for awful grepping. Call the global variable "ifnetlist" from now on. There used to be kvm(3) consumers in base picking up this symbol, but those have long been converted to other interfaces. A few potential ports users remain, same deal as sys/net/if_var.h r1.116 "Remove struct ifnet's unused if_switchport member": they get bumped. Previous users pointed out by deraadt OK bluhm
2022-08-29Use struct refcnt for interface address reference counting.Alexander Bluhm
There was a crash due to use after free of the ifa although it is ref counted. As ifa_refcnt was a simple integer increment, there may be a path where multiple CPUs access it concurrently. So change to struct refcnt which is MP safe and provides dt(4) leak debugging. Link level address for IPsec enc(4) and various MPLS interfaces is special. There ifa is part of struct sc. Use refcount anyway and add a panic to detect use after free. bug report stsp@; OK mvs@
2022-08-06Clean up the netlock macros. Merge NET_RLOCK_IN_SOFTNET andAlexander Bluhm
NET_RLOCK_IN_IOCTL, which have the same implementation. The R and W are hard to see, call the new macro NET_LOCK_SHARED. Rename the opposite assertion from NET_ASSERT_WLOCKED to NET_ASSERT_LOCKED_EXCLUSIVE. Update some outdated comments about net locking. OK mpi@ mvs@
2022-02-25Reported-by: syzbot+1b5b209ce506db4d411d@syzkaller.appspotmail.comPhilip Guenther
Revert the pr_usrreqs move: syzkaller found a NULL pointer deref and I won't be available to monitor for followup issues for a bit
2022-02-25in6_ioctl() is declared in in6_var.h as it's used in if_umb.c, soPhilip Guenther
don't declare it again in the .c file ok dlg@ mvs@ bluhm@
2022-01-02spellingJonathan Gray
ok jmc@ reads ok tb@
2021-03-10spellingJonathan Gray
ok gnezdo@ semarie@ mpi@
2020-08-07The IPv6 source address selection rewrite had one (known) differenceFlorian Obser
to the previous behavior: In case of a tie the new implementation would keep the current best address while the old implementation replaced the best address. Since IPv6 addresses are stored in a TAILQ this meant that the rewrite would use the "oldest" address while the previous behavior was to use the "newest". RFC 6724 section 5 has no opinion which one is better and leaves the tie break up to implementers. naddy found out the hard way that this breaks his IPv6 connectivity in case of flash renumbering events when the link on his cpe flaps and a new prefix is used since we would always pick an old address. While we could pick the newest address in a tie break this feels too much like an implementation detail, a solution much more in the spirit of IPv6 is to pick the address with the highest preferred lifetime (or valid lifetime in case of another tie). very patient testing naddy@
2020-08-04Validate input given to ioctl(SIOCAIFADDR_IN6) like NetBSD already does.anton
Fixes a bunch of panics reported by syzkaller. ok florian@ Reported-by: syzbot+02f2e07964a89ab65ea4@syzkaller.appspotmail.com Reported-by: syzbot+c26b058a499ce38f689f@syzkaller.appspotmail.com Reported-by: syzbot+62af76d8cb7c09ac017c@syzkaller.appspotmail.com Reported-by: syzbot+d70144b3ae2ec068e318@syzkaller.appspotmail.com Reported-by: syzbot+3c87ca9873bfd0492f5c@syzkaller.appspotmail.com Reported-by: syzbot+323549177062adb80f84@syzkaller.appspotmail.com Reported-by: syzbot+e745c1c29d960337ce14@syzkaller.appspotmail.com Reported-by: syzbot+91da988a445013baf925@syzkaller.appspotmail.com Reported-by: syzbot+747cbcbbed6318542061@syzkaller.appspotmail.com Reported-by: syzbot+ca5efa23e00130bc8000@syzkaller.appspotmail.com Reported-by: syzbot+731ab8c9a0342ace4189@syzkaller.appspotmail.com Reported-by: syzbot+6c80b815a0ff8f09be69@syzkaller.appspotmail.com Reported-by: syzbot+7939d2c4bc9a5dfa707a@syzkaller.appspotmail.com Reported-by: syzbot+e893fb0259640a314d06@syzkaller.appspotmail.com Reported-by: syzbot+b6a3447070ae8ffcb125@syzkaller.appspotmail.com Reported-by: syzbot+23c0824b688f28c79c1b@syzkaller.appspotmail.com Reported-by: syzbot+6cc72412d8ddcf87f8a1@syzkaller.appspotmail.com
2020-07-28Rewrite IPv6 source address selection in terms of the 8 rules given inFlorian Obser
RFC 6724 section 5. This simplifies the code considerably while extensive testing shows no change in behaviour. It is time to volunteer some more testers. OK denis@ some time ago.
2020-07-03Rename IN6_IFF_PRIVACY to IN6_IFF_TEMPORARY.Florian Obser
This is the name the other BSDs use for this, there is no reason to be different, the IPv6 RFCs call these addresses temporary, and some software in ports wants to use this as well. Most recently pointed out for firefox by landry. OK claudio, sthen
2020-06-30Fix two places where carp backup state is misspelled in comments.Sebastian Benoit
ok claudio@
2020-06-24kernel: use gettime(9)/getuptime(9) in lieu of time_second(9)/time_uptime(9)cheloha
time_second(9) and time_uptime(9) are widely used in the kernel to quickly get the system UTC or system uptime as a time_t. However, time_t is 64-bit everywhere, so it is not generally safe to use them on 32-bit platforms: you have a split-read problem if your hardware cannot perform atomic 64-bit reads. This patch replaces time_second(9) with gettime(9), a safer successor interface, throughout the kernel. Similarly, time_uptime(9) is replaced with getuptime(9). There is a performance cost on 32-bit platforms in exchange for eliminating the split-read problem: instead of two register reads you now have a lockless read loop to pull the values from the timehands. This is really not *too* bad in the grand scheme of things, but compared to what we were doing before it is several times slower. There is no performance cost on 64-bit (__LP64__) platforms. With input from visa@, dlg@, and tedu@. Several bugs squashed by visa@. ok kettenis@
2020-05-27Document the various flavors of NET_LOCK() and rename the reader version.Martin Pieuchot
Since our last concurrency mistake only ioctl(2) ans sysctl(2) code path take the reader lock. This is mostly for documentation purpose as long as the softnet thread is converted back to use a read lock. dlg@ said that comments should be good enough. ok sashan@
2020-03-15Guard SIOCDELMULTI if_ioctl calls with KERNEL_LOCK() where the call isVisa Hankala
made from socket close path. Most device drivers are not MP-safe yet, and the closing of AF_INET and AF_INET6 sockets is no longer under the kernel lock. This fixes a panic seen by jcs@. OK mpi@
2019-11-18Accept inet6 address with missing sa_len for the get ioctl(2).Alexander Bluhm
dhcpcd from ports uses SIOCGIFAFLAG_IN6 without setting sin6_len. OK deraadt@ millert@
2019-11-11Kernel is missing propper input validation when configuring IPv6Alexander Bluhm
addresses. Implement in6_sa2sin6() to validate inet6 address family and address length. The SIOCGIFDSTADDR_IN6, SIOCGIFNETMASK_IN6, SIOCGIFAFLAG_IN6, SIOCGIFALIFETIME_IN6, and SIOCDIFADDR_IN6 ioctl(2) are safe now. OK visa@
2019-11-08convert interface address change hooks to tasks and a task_list.David Gwynne
this follows what's been done for detach and link state hooks, and makes handling of hooks generally more robust. address hooks are a bit different to detach/link state hooks in that there's only a few things that register hooks (carp, pf, vxlan), but a lot of places to run the hooks (lots of ipv4 and ipv6 address configuration). an address hook cookie was in struct pfi_kif, which is part of the pf abi. rather than break pfctl -sI, this maintains the void * used for the cookie and uses it to store a task, which is then used as intended with the new api.
2019-10-22Fix white spaces and use __func__ in printf().Alexander Bluhm
2019-02-13change rt_ifa_add and rt_ifa_del so they take an rdomain argument.David Gwynne
this allows mpls interfaces (mpe, mpw) to pass the rdomain they wish the local label to be in, rather than have it implicitly forced to 0 by these functions. right now they'll pass 0, but it will soon be possible to have them rx packets in other rdomains. previously the functions used ifp->if_rdomain for the rdomain. everything other than mpls still passes ifp->if_rdomain. ok mpi@
2019-02-10remove the implict RTF_MPATH flag that rt_ifa_add() sets on new routes.David Gwynne
MPLS interfaces (ab)use rt_ifa_add for adding the local MPLS label that they listen on for incoming packets, while every other use of rt_ifa_add is for adding addresses on local interfaces. MPLS does this cos the addresses involved are in basically the same shape as ones used for setting up local addresses. It is appropriate for interfaces to want RTF_MPATH on local addresses, but in the MPLS case it means you can have multiple local things listening on the same label, which doesn't actually work. mpe in particular keeps track of in use labels to it can handle collisions, however, mpw does not. It is currently possible to have multiple mpw interfaces on the same local label, and sharing the same label as mpe or possible normal forwarding labels. Moving the RTF_MPATH flag out of rt_ifa_add means all the callers that still want it need to pass it themselves. The mpe and mpw callers are left alone without the flag, and will now get EEXIST from rt_ifa_add when a label is already in use. ok (and a huge amount of patience and help) mpi@ claudio@ is ok with the idea, but saw a much much earlier solution to the problem
2018-10-05Do not join node information multicast group (RFC 4620).Florian Obser
Benno removed code to answer ICMP queries over 4 years ago. Aham Brahmasmi (aham.brahmasmi AT gmx.com) points out that we still joined the group though. OK sthen, bluhm, kn
2018-05-12Make the code a bit easier on the eye by factoring repeated embeddedTheo Buehler
scope check and clearing of the scope id into separate functions. input & ok visa, mpi
2018-05-06Nuke unused ia6_createtime struct member.Florian Obser
OK tb
2018-05-06Continue refactoring and cleanup of in6_ioctl().Theo Buehler
Hoist privilege check to the top and split out handling of SIOCAIFADDR_IN6 and SIOCDIFADDR_IN6 into a separate function. Merge tangled switches and simplify the code paths. tested by hrvoje ok visa
2018-05-04Split handling of SIOCGIF*_IN6 into a separate function in6_ioctl_get()Theo Buehler
that only needs a read lock. Tested by hrvoje ok visa
2018-05-02Push the NET_LOCK() down in in6_control() similar to what was doneTheo Buehler
for in_control(). Protect mrt6_ioctl() and nd6_ioctl() with a read lock and in6_ioctl with the NET_LOCK() while establishing a single exit point. tested by kn ok florian, mpi, visa
2018-04-24Make the ramdisks compile again, we don't have MROUTING on them.Florian Obser
Found the hard way.
2018-04-24Push NET_LOCK down in the default ifioctl case.Paul Irofti
For the PRU_CONTROL bit the NET_LOCK surrounds in[6]_control() and on the ENOTSUPP case we guard the driver if_ioctl functions. OK mpi@
2018-04-24Run duplicate address detection again if an existing address getsFlorian Obser
updated from userland that was marked duplicated or tentative. Otherwise we would just lose the duplicated / tentative state and assume that the address is now unique and usable. OK kn
2017-11-23Replace non mp-safe carp_iamatch6() with mp-safe carp_iamatch().Martin Pieuchot
They have the same functionnality since friehm@ cleaned up balancing code. ok florian@, visa@, patrick@, bluhm@, jmatthew@
2017-11-04Stop calling ifp->if_ioctl() inside in{,6}_ioctl().Martin Pieuchot
Instead return EOPNOTSUPP and call it from ifioctl(). This will help getting per-driver ioctl routines outside of need the NET_LOCK(). While here always return ENXIO when ``ifp'' is NULL. ok visa@, florian@
2017-11-02Over 17 years is probably 'a while...'Florian Obser
Also it does not change behaviour. OK jca
2017-10-26Kill deprecated IPv6 ioctl(2)s.Martin Pieuchot
ok florian@, sthen@, jsg@
2017-10-24Remove some more tests checking for a non-NULL `ifp->if_ioctl'.Martin Pieuchot
if_attach() enforces it is properly defined.
2017-10-24Remove support for never used ioctls originating from KAME.Martin Pieuchot
ok florian@, claudio@, bluhm@
2017-10-20Do not test if if_ioctl is NULL, it isn't.Martin Pieuchot
ok florian@, claudio@, visa@, bluhm@