summaryrefslogtreecommitdiff
path: root/sys/netinet6/udp6_usrreq.c
AgeCommit message (Collapse)Author
2022-11-04inpcb: rename functions to in6pcb_*ozaki-r
2022-11-04inpcb: rename functions to inpcb_*ozaki-r
Inspired by rmind-smpnet patches.
2022-10-28inpcb: separate inpcb again to reduce the size of PCB for IPv4ozaki-r
The data size of PCB for IPv4 increased because of the merge of struct in6pcb. The change decreases the size to the original size by separating struct inpcb (again). struct in4pcb and in6pcb that embed struct inpcb are introduced. Even after the separation, users don't need to realize the separation and only have to use some macros to access dedicated data. For example, inp->inp_laddr is now accessed through in4p_laddr(inp).
2022-10-28inpcb: integrate data structures of PCB into oneozaki-r
Data structures of network protocol control blocks (PCBs), i.e., struct inpcb, in6pcb and inpcb_hdr, are not organized well. Users of the data structures have to handle them separately and thus the code is cluttered and duplicated. The commit integrates the data structures into one, struct inpcb. As a result, users of PCBs only have to handle just one data structure, so the code becomes simple. One drawback is that the data size of PCB for IPv4 increases by 40 bytes (from 248 bytes to 288 bytes).
2021-02-19- Make ALIGNED_POINTER use __alignof(t) instead of sizeof(t). This is morechristos
correct because it works with non-primitive types and provides the ABI alignment for the type the compiler will use. - Remove all the *_HDR_ALIGNMENT macros and asserts - Replace POINTER_ALIGNED_P with ACCESSIBLE_POINTER which is identical to ALIGNED_POINTER, but returns that the pointer is always aligned if the CPU supports unaligned accesses. [ as proposed in tech-kern ]
2021-02-14- centralize header align and pullup into a single inline functionchristos
- use a single macro to align pointers and expose the alignment, instead of hard-coding 3 in 1/2 the macros. - fix an issue in the ipv6 lt2p where it was aligning for ipv4 and pulling for ipv6.
2020-08-20[ozaki-r] Changes to the kernel core for wireguardriastradh
2019-02-25Fix the order in udp6_attach: soreserve should be called beforemaxv
in6_pcballoc, otherwise if it fails there is still a PCB attached, and we hit a KASSERT in socreate. In !DIAGNOSTIC this would have caused a memory leak. By the way I find the splsoftnet highly suspicious, in6_pcballoc already does that. Triggered by SyzKaller. Reported-by: syzbot+7bace612ca3cc3e124f8@syzkaller.appspotmail.com
2019-01-28Fix memory leaks pointed out by Ilja Van Sprundel: allmartin
sendoob() functions are expted to free both passed mbuf chains.
2018-12-27Remove unused arguments.maxv
2018-11-22Support IPv6 NAT-T. Implemented by hsuenaga@IIJ and ohishi@IIJ.knakahara
Add ATF later.
2018-11-06Restore the length check of a sockaddr passed from userland at udp6_outputozaki-r
A sockaddr with invalid length could be passed to the network stack resulting in a kernel panic like this: panic: sockaddr_copy: source too long, 28 < 128 bytes fatal breakpoint trap in supervisor mode trap type 1 code 0 rip 0xffffffff80216c35 cs 0x8 rflags 0x246 cr2 0x7f7ff7ef3000 ilevel 0x4 rsp 0xffff80003308b690 curlwp 0xfffffe803e11ca40 pid 48.1 lowest kstack 0xffff8000330852c0 Stopped in pid 48.1 (a.out) at netbsd:breakpoint+0x5: leave db{1}> bt breakpoint() at netbsd:breakpoint+0x5 vpanic() at netbsd:vpanic+0x140 panic() at netbsd:panic+0x3c sockaddr_copy() at netbsd:sockaddr_copy+0x95 rtcache_setdst() at netbsd:rtcache_setdst+0x73 rtcache_lookup2() at netbsd:rtcache_lookup2+0x56 in6_selectroute() at netbsd:in6_selectroute+0x184 in6_selectsrc() at netbsd:in6_selectsrc+0x119 udp6_output() at netbsd:udp6_output+0x25e udp6_send_wrapper() at netbsd:udp6_send_wrapper+0x8a sosend() at netbsd:sosend+0x7bf do_sys_sendmsg_so() at netbsd:do_sys_sendmsg_so+0x28e do_sys_sendmsg() at netbsd:do_sys_sendmsg+0x89 sys_sendto() at netbsd:sys_sendto+0x5c syscall() at netbsd:syscall+0x1ed --- syscall (number 133) --- 7f7ff790173a: Reported by Paul Ripke
2018-11-04Fix error path in ip6 source address selection.mlelstv
in6_selectsrc previously returned a pointer to an ipv6 address, the pointer was NULL in case of an error and is checked later instead of the also returned error code. When in6_selectsrc was changed to store the address into a buffer, the error code was still ignored, but the buffer pointer was never set to NULL. As a result send() to an ipv6 address on a system that isn't configured for ipv6 no longer returns the expected EADDRAVAIL but fails later in ip6_output with EOPNOTSUPP when trying to send from an unspecified address. The wrong error code caused BIND to log the unexpected errors.
2018-04-28Remove unused ipsec_var.h includes.maxv
2018-04-18Remove misleading comments.maxv
2018-04-12Remove misleading comment; we're just checking the SP, not verifying themaxv
AH/ESP payload. While here style a bit.
2018-03-19socket: report receive buffer overflowsroy
Add soroverflow() which increments the overflow counter, sets so_error to ENOBUFS and wakes the receive socket up. Replace all code that manually increments this counter with soroverflow(). Add soroverflow() to raw_input(). This allows userland to detect route(4) overflows so it can re-sync with the current state.
2018-02-28Remove unused ipsec_private.h includes.maxv
2018-02-28Remove duplicate IPSEC_STATINC(IPSEC_STAT_IN_POLVIO), ipsec_in_rejectmaxv
already increases it. IPSEC6_STATINC is now unused, so remove it too.
2018-02-26Dedup: merge ipsec4_in_reject and ipsec6_in_reject into ipsec_in_reject.maxv
While here fix misleading comment. ok ozaki-r@
2018-02-08Remove the IN6_IS_ADDR_V4MAPPED checks in the protocol functions. Theymaxv
are useless, because the IPv6 entry point (ip6_input) already performs them. The checks were first added in the protocol functions: Wed Dec 22 04:03:02 1999 UTC (18 years, 1 month ago) by itojun "drop IPv6 packets with v4 mapped address on src/dst. they are illegal and may be used to fool IPv6 implementations (by using ::ffff:127.0.0.1 as source you may be able to pretend the packet is from local node)" Shortly afterwards they were also added in the IPv6 entry point, but where not removed from the protocol functions: Mon Jan 31 10:33:22 2000 UTC (18 years ago) by itojun "be proactive about malicious packet on the wire. we fear that v4 mapped address to be used as a tool to hose security filters (like bypassing "local host only" filter by using ::ffff:127.0.0.1)." OpenBSD did the same a few months ago. FreeBSD has never had these checks.
2018-02-08pr_send can be given a NULL lwp. It looks like themaxv
control != NULL && lwp == NULL condition is never supposed to happen, but add a panic for safety.
2018-02-08Move udp6_output() into udp6_usrreq.c, and remove udp6_output.c. This ismaxv
more consistent with IPv4, and there is no good reason for keeping a separate file only for one function. FreeBSD did the same.
2018-02-08Style, no functional change.maxv
2017-07-06Merge the two copies SO_TIMESTAMP/SO_OTIMESTAMP processing to a singlechristos
function, and add a SOOPT_TIMESTAMP define reducing compat pollution from 5 places to 1.
2017-04-20Remove unnecessary NULL checks for inp_socket and in6p_socketozaki-r
They cannot be NULL except for programming errors.
2017-04-20Simplify logic of udp4_sendup and udp6_sendupozaki-r
They are always passed a socket with the same protocol faimiliy as its own: AF_INET for udp4_sendup and AF_INET6 for udp6_sendup.
2017-01-24Tweak softnet_lock and NET_MPSAFEozaki-r
- Don't hold softnet_lock in some functions if NET_MPSAFE - Add softnet_lock to sysctl_net_inet_icmp_redirtimeout - Add softnet_lock to expire_upcalls of ip_mroute.c - Restore softnet_lock for in{,6}_pcbpurgeif{,0} if NET_MPSAFE - Mark some softnet_lock for future work
2016-11-18fix: "ifconfig destory" can stalls when "ifconfig" is done parallel.knakahara
This problem occurs only if NET_MPSAFE on. ifconfig destroy side: kernel entry point is ifioctl => if_clone_destroy. pr_purgeif() acquires softnet_lock, and then ifa_remove() calls pserialize_perform() holding softnet_lock. ifconfig side: kernel entry point is socreate. pr_attach()(udp_attach_wrapper()) calls sosetlock(). In this call path, sosetlock() try to acquire softnet_lock. These can cause dead lock.
2016-11-15Enforce alignment requirements that are violated in some cases.mlelstv
For machines that don't need strict alignment (i386,amd64,vax,m68k) this is a no-op. Fixes PR kern/50766 but should be improved.
2016-07-15Use sin6tosa and sin6tocsa macrosozaki-r
No functional change.
2016-06-10Avoid storing a pointer of an interface in a mbufozaki-r
Having a pointer of an interface in a mbuf isn't safe if we remove big kernel locks; an interface object (ifnet) can be destroyed anytime in any packet processing and accessing such object via a pointer is racy. Instead we have to get an object from the interface collection (ifindex2ifnet) via an interface index (if_index) that is stored to a mbuf instead of an pointer. The change provides two APIs: m_{get,put}_rcvif_psref that use psref(9) for sleep-able critical sections and m_{get,put}_rcvif that use pserialize(9) for other critical sections. The change also adds another API called m_get_rcvif_NOMPSAFE, that is NOT MP-safe and for transition moratorium, i.e., it is intended to be used for places where are not planned to be MP-ified soon. The change adds some overhead due to psref to performance sensitive paths, however the overhead is not serious, 2% down at worst. Proposed on tech-kern and tech-net.
2016-04-26Sweep unnecessary route.h inclusionsozaki-r
2015-08-24sprinkle _KERNEL_OPTpooka
2015-05-02make connect syscall use sockaddr_big and modify pr_{send,connect}rtr
nam parameter type from buf * to sockaddr *. final commit for parameter type changes to protocol user requests * bump kernel version to 7.99.15 for parameter type changes to pr_{send,connect}
2015-04-26remove pr_generic from struct pr_usrreqs and all implementations ofrtr
pr_generic in protocols. bump to 7.99.13 approved by rmind@
2015-04-24make accept, getsockname and getpeername syscalls use sockaddr_big and modifyrtr
pr_{accept,sockname,peername} nam parameter type from mbuf * to sockaddr *. * retained use of mbuftypes[MT_SONAME] for now. * bump to netbsd version 7.99.12 for parameter type change. patch posted to tech-net@ 2015/04/19
2015-04-03* change pr_bind to accept struct sockaddr * instead of struct mbuf *rtr
* update protocol bind implementations to use/expect sockaddr * instead of mbuf * * introduce sockaddr_big struct for storage of addr data passed via sys_bind; sockaddr_big is of sufficient size and alignment to accommodate all addr data sizes received. * modify sys_bind to allocate sockaddr_big instead of using an mbuf. * bump kernel version to 7.99.9 for change to pr_bind() parameter type. Patch posted to tech-net@ http://mail-index.netbsd.org/tech-net/2015/03/15/msg005004.html The choice to use a new structure sockaddr_big has been retained since changing sockaddr_storage size would lead to unnecessary ABI change. The use of the new structure does not preclude future work that increases the size of sockaddr_storage and at that time sockaddr_big may be trivially replaced. Tested by mrg@ and myself, discussed with rmind@, posted to tech-net@
2015-03-30Tidy up opt_ipsec.h inclusionsozaki-r
2014-08-09split PRU_CONNECT2 & PRU_PURGEIF function out of pr_generic() usrreqrtr
switches and put into separate functions - always KASSERT(solocked(so)) even if not implemented (for PRU_CONNECT2 only) - replace calls to pr_generic() with req = PRU_CONNECT2 with calls to pr_connect2() - replace calls to pr_generic() with req = PRU_PURGEIF with calls to pr_purgeif() put common code from unp_connect2() (used by unp_connect() into unp_connect1() and call out to it when needed patch only briefly reviewed by rmind@
2014-08-08split PRU_RCVD function out of pr_generic() usrreq switches and put intortr
separate functions - always KASSERT(solocked(so)) even if not implemented - replace calls to pr_generic() with req = PRU_RCVD with calls to pr_rcvd()
2014-08-05split PRU_SEND function out of pr_generic() usrreq switches and put intortr
separate functions xxx_send(struct socket *, struct mbuf *, struct mbuf *, struct mbuf *, struct lwp *) - always KASSERT(solocked(so)) even if not implemented - replace calls to pr_generic() with req = PRU_SEND with calls to pr_send() rename existing functions that operate on PCB for consistency (and to free up their names for xxx_send() PRUs - l2cap_send() -> l2cap_send_pcb() - sco_send() -> sco_send_pcb() - rfcomm_send() -> rfcomm_send_pcb() patch reviewed by rmind
2014-08-05revert the removal of struct lwp * parameter from bind, listen and connectrtr
user requests. this should resolve the issue relating to nfs client hangs presented recently by wiz on current-users@
2014-07-31split PRU_DISCONNECT, PRU_SHUTDOWN and PRU_ABORT function out ofrtr
pr_generic() usrreq switches and put into separate functions xxx_disconnect(struct socket *) xxx_shutdown(struct socket *) xxx_abort(struct socket *) - always KASSERT(solocked(so)) even if not implemented - replace calls to pr_generic() with req = PRU_{DISCONNECT,SHUTDOWN,ABORT} with calls to pr_{disconnect,shutdown,abort}() respectively rename existing internal functions used to implement above functionality to permit use of the names for xxx_{disconnect,shutdown,abort}(). - {l2cap,sco,rfcomm}_disconnect() -> {l2cap,sco,rfcomm}_disconnect_pcb() - {unp,rip,tcp}_disconnect() -> {unp,rip,tcp}_disconnect1() - unp_shutdown() -> unp_shutdown1() patch reviewed by rmind
2014-07-30split PRU_CONNECT function out of pr_generic() usrreq switches and putrtr
into seaparate functions xxx_listen(struct socket *, struct mbuf *) - always KASSERT(solocked(so)) and KASSERT(nam != NULL) - replace calls to pr_generic() with req = PRU_CONNECT with pr_connect() - rename existin {l2cap,sco,rfcomm}_connect() to {l2cap,sco,rfcomm}_connect_pcb() respectively to permit naming consistency with other protocols functions. - drop struct lwp * parameter from unp_connect() and at_pcbconnect() and use curlwp instead where appropriate. patch reviewed by rmind
2014-07-24split PRU_BIND and PRU_LISTEN function out of pr_generic() usrreqrtr
switches and put into separate functions xxx_bind(struct socket *, struct mbuf *) xxx_listen(struct socket *) - always KASSERT(solocked(so)) even if not implemented - replace calls to pr_generic() with req = PRU_BIND with call to pr_bind() - replace calls to pr_generic() with req = PRU_LISTEN with call to pr_listen() - drop struct lwp * parameter from at_pcbsetaddr(), in_pcbbind() and unp_bind() and always use curlwp. rename existing functions that operate on PCB for consistency (and to free up their names for xxx_{bind,listen}() PRUs - l2cap_{bind,listen}() -> l2cap_{bind,listen}_pcb() - sco_{bind,listen}() -> sco_{bind,listen}_pcb() - rfcomm_{bind,listen}() -> rfcomm_{bind,listen}_pcb() patch reviewed by rmind welcome to netbsd 6.99.48
2014-07-23split PRU_SENDOOB and PRU_RCVOOB function out of pr_generic() usrreqrtr
switches and put into separate functions xxx_sendoob(struct socket *, struct mbuf *, struct mbuf *) xxx_recvoob(struct socket *, struct mbuf *, int) - always KASSERT(solocked(so)) even if request is not implemented - replace calls to pr_generic() with req = PRU_{SEND,RCV}OOB with calls to pr_{send,recv}oob() respectively. there is still some tweaking of m_freem(m) and m_freem(control) to come for consistency. not performed with this commit for clarity. reviewed by rmind
2014-07-09* split PRU_ACCEPT function out of pr_generic() usrreq switches and putrtr
into a separate function xxx_accept(struct socket *, struct mbuf *) note: future cleanup will take place to remove struct mbuf parameter type and replace it with a more appropriate type. patch reviewed by rmind
2014-07-09* split PRU_PEERADDR and PRU_SOCKADDR function out of pr_generic()rtr
usrreq switches and put into separate functions xxx_{peer,sock}addr(struct socket *, struct mbuf *). - KASSERT(solocked(so)) always in new functions even if request is not implemented - KASSERT(pcb != NULL) and KASSERT(nam) if the request is implemented and not for tcp. * for tcp roll #ifdef KPROF and #ifdef DEBUG code from tcp_usrreq() into easier to cut & paste functions tcp_debug_capture() and tcp_debug_trace() - functions provided by rmind - remaining use of PRU_{PEER,SOCK}ADDR #define to be removed in a future commit. * rename netbt functions to permit consistency of pru function names (as has been done with other requests already split out). - l2cap_{peer,sock}addr() -> l2cap_{peer,sock}_addr_pcb() - rfcomm_{peer,sock}addr() -> rfcomm_{peer,sock}_addr_pcb() - sco_{peer,sock}addr() -> sco_{peer,sock}_addr_pcb() * split/refactor do_sys_getsockname(lwp, fd, which, nam) into two functions do_sys_get{peer,sock}name(fd, nam). - move PRU_PEERADDR handling into do_sys_getpeername() from do_sys_getsockname() - have svr4_stream directly call do_sys_get{sock,peer}name() respectively instead of providing `which' & fix a DPRINTF string that incorrectly wrote "getpeername" when it meant "getsockname" - fix sys_getpeername() and sys_getsockname() to call do_sys_get{sock,peer}name() without `which' and `lwp' & adjust comments - bump kernel version for removal of lwp & which parameters from do_sys_getsockname() note: future cleanup to remove struct mbuf * abuse in xxx_{peer,sock}name() still to come, not done in this commit since it is easier to do post split. patch reviewed by rmind welcome to 6.99.47
2014-07-07* sprinkle KASSERT(solocked(so)); in all pr_stat() functions.rtr
* fix remaining inconsistent struct socket parameter names.