2015-04-27 00:40:48 +03:00
|
|
|
/* $NetBSD: link_proto.c,v 1.27 2015/04/26 21:40:48 rtr Exp $ */
|
Take steps to hide the radix_node implementation of the forwarding table
from the forwarding table's users:
Introduce rt_walktree() for walking the routing table and
applying a function to each rtentry. Replace most
rn_walktree() calls with it.
Use rt_getkey()/rt_setkey() to get/set a route's destination.
Keep a pointer to the sockaddr key in the rtentry, so that
rtentry users do not have to grovel in the radix_node for
the key.
Add a RTM_GET method to rtrequest. Use that instead of
radix_node lookups in, e.g., carp(4).
Add sys/net/link_proto.c, which supplies sockaddr routines for
link-layer socket addresses (sockaddr_dl).
Cosmetic:
Constify. KNF. Stop open-coding LIST_FOREACH, TAILQ_FOREACH,
et cetera. Use NULL instead of 0 for null pointers. Use
__arraycount(). Reduce gratuitous parenthesization.
Stop using variadic arguments for rip6_output(), it is
unnecessary.
Remove the unnecessary rtentry member rt_genmask and the
code to maintain it, since nothing actually used it.
Make rt_maskedcopy() easier to read by using meaningful variable
names.
Extract a subroutine intern_netmask() for looking up a netmask in
the masks table.
Start converting backslash-ridden IPv6 macros in
sys/netinet6/in6_var.h into inline subroutines that one
can read without special eyeglasses.
One functional change: when the kernel serves an RTM_GET, RTM_LOCK,
or RTM_CHANGE request, it applies the netmask (if supplied) to a
destination before searching for it in the forwarding table.
I have changed sys/netinet/ip_carp.c, carp_setroute(), to remove
the unlawful radix_node knowledge.
Apart from the changes to carp(4), netiso, ATM, and strip(4), I
have run the changes on three nodes in my wireless routing testbed,
which involves IPv4 + IPv6 dynamic routing acrobatics, and it's
working beautifully so far.
2007-07-20 00:48:52 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1982, 1986, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* @(#)uipc_proto.c 8.2 (Berkeley) 2/14/95
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2015-04-27 00:40:48 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: link_proto.c,v 1.27 2015/04/26 21:40:48 rtr Exp $");
|
Take steps to hide the radix_node implementation of the forwarding table
from the forwarding table's users:
Introduce rt_walktree() for walking the routing table and
applying a function to each rtentry. Replace most
rn_walktree() calls with it.
Use rt_getkey()/rt_setkey() to get/set a route's destination.
Keep a pointer to the sockaddr key in the rtentry, so that
rtentry users do not have to grovel in the radix_node for
the key.
Add a RTM_GET method to rtrequest. Use that instead of
radix_node lookups in, e.g., carp(4).
Add sys/net/link_proto.c, which supplies sockaddr routines for
link-layer socket addresses (sockaddr_dl).
Cosmetic:
Constify. KNF. Stop open-coding LIST_FOREACH, TAILQ_FOREACH,
et cetera. Use NULL instead of 0 for null pointers. Use
__arraycount(). Reduce gratuitous parenthesization.
Stop using variadic arguments for rip6_output(), it is
unnecessary.
Remove the unnecessary rtentry member rt_genmask and the
code to maintain it, since nothing actually used it.
Make rt_maskedcopy() easier to read by using meaningful variable
names.
Extract a subroutine intern_netmask() for looking up a netmask in
the masks table.
Start converting backslash-ridden IPv6 macros in
sys/netinet6/in6_var.h into inline subroutines that one
can read without special eyeglasses.
One functional change: when the kernel serves an RTM_GET, RTM_LOCK,
or RTM_CHANGE request, it applies the netmask (if supplied) to a
destination before searching for it in the forwarding table.
I have changed sys/netinet/ip_carp.c, carp_setroute(), to remove
the unlawful radix_node knowledge.
Apart from the changes to carp(4), netiso, ATM, and strip(4), I
have run the changes on three nodes in my wireless routing testbed,
which involves IPv4 + IPv6 dynamic routing acrobatics, and it's
working beautifully so far.
2007-07-20 00:48:52 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/domain.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/raw_cb.h>
|
2008-05-13 22:09:22 +04:00
|
|
|
#include <net/route.h>
|
Take steps to hide the radix_node implementation of the forwarding table
from the forwarding table's users:
Introduce rt_walktree() for walking the routing table and
applying a function to each rtentry. Replace most
rn_walktree() calls with it.
Use rt_getkey()/rt_setkey() to get/set a route's destination.
Keep a pointer to the sockaddr key in the rtentry, so that
rtentry users do not have to grovel in the radix_node for
the key.
Add a RTM_GET method to rtrequest. Use that instead of
radix_node lookups in, e.g., carp(4).
Add sys/net/link_proto.c, which supplies sockaddr routines for
link-layer socket addresses (sockaddr_dl).
Cosmetic:
Constify. KNF. Stop open-coding LIST_FOREACH, TAILQ_FOREACH,
et cetera. Use NULL instead of 0 for null pointers. Use
__arraycount(). Reduce gratuitous parenthesization.
Stop using variadic arguments for rip6_output(), it is
unnecessary.
Remove the unnecessary rtentry member rt_genmask and the
code to maintain it, since nothing actually used it.
Make rt_maskedcopy() easier to read by using meaningful variable
names.
Extract a subroutine intern_netmask() for looking up a netmask in
the masks table.
Start converting backslash-ridden IPv6 macros in
sys/netinet6/in6_var.h into inline subroutines that one
can read without special eyeglasses.
One functional change: when the kernel serves an RTM_GET, RTM_LOCK,
or RTM_CHANGE request, it applies the netmask (if supplied) to a
destination before searching for it in the forwarding table.
I have changed sys/netinet/ip_carp.c, carp_setroute(), to remove
the unlawful radix_node knowledge.
Apart from the changes to carp(4), netiso, ATM, and strip(4), I
have run the changes on three nodes in my wireless routing testbed,
which involves IPv4 + IPv6 dynamic routing acrobatics, and it's
working beautifully so far.
2007-07-20 00:48:52 +04:00
|
|
|
|
|
|
|
static int sockaddr_dl_cmp(const struct sockaddr *, const struct sockaddr *);
|
2014-05-19 06:51:24 +04:00
|
|
|
static int link_attach(struct socket *, int);
|
|
|
|
static void link_detach(struct socket *);
|
2015-04-25 01:32:37 +03:00
|
|
|
static int link_accept(struct socket *, struct sockaddr *);
|
2015-04-03 23:01:07 +03:00
|
|
|
static int link_bind(struct socket *, struct sockaddr *, struct lwp *);
|
2014-08-05 09:24:26 +04:00
|
|
|
static int link_listen(struct socket *, struct lwp *);
|
|
|
|
static int link_connect(struct socket *, struct mbuf *, struct lwp *);
|
2014-08-09 09:33:00 +04:00
|
|
|
static int link_connect2(struct socket *, struct socket *);
|
split PRU_DISCONNECT, PRU_SHUTDOWN and PRU_ABORT function out of
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-31 07:39:35 +04:00
|
|
|
static int link_disconnect(struct socket *);
|
|
|
|
static int link_shutdown(struct socket *);
|
|
|
|
static int link_abort(struct socket *);
|
2014-07-01 09:49:18 +04:00
|
|
|
static int link_ioctl(struct socket *, u_long, void *, struct ifnet *);
|
2014-07-06 20:06:19 +04:00
|
|
|
static int link_stat(struct socket *, struct stat *);
|
2015-04-25 01:32:37 +03:00
|
|
|
static int link_peeraddr(struct socket *, struct sockaddr *);
|
|
|
|
static int link_sockaddr(struct socket *, struct sockaddr *);
|
2014-08-08 07:05:44 +04:00
|
|
|
static int link_rcvd(struct socket *, int, struct lwp *);
|
2014-07-31 17:21:33 +04:00
|
|
|
static int link_recvoob(struct socket *, struct mbuf *, int);
|
2014-08-05 11:55:31 +04:00
|
|
|
static int link_send(struct socket *, struct mbuf *, struct mbuf *,
|
|
|
|
struct mbuf *, struct lwp *);
|
2014-07-31 17:21:33 +04:00
|
|
|
static int link_sendoob(struct socket *, struct mbuf *, struct mbuf *);
|
2014-08-09 09:33:00 +04:00
|
|
|
static int link_purgeif(struct socket *, struct ifnet *);
|
2008-05-13 22:09:22 +04:00
|
|
|
static void link_init(void);
|
Take steps to hide the radix_node implementation of the forwarding table
from the forwarding table's users:
Introduce rt_walktree() for walking the routing table and
applying a function to each rtentry. Replace most
rn_walktree() calls with it.
Use rt_getkey()/rt_setkey() to get/set a route's destination.
Keep a pointer to the sockaddr key in the rtentry, so that
rtentry users do not have to grovel in the radix_node for
the key.
Add a RTM_GET method to rtrequest. Use that instead of
radix_node lookups in, e.g., carp(4).
Add sys/net/link_proto.c, which supplies sockaddr routines for
link-layer socket addresses (sockaddr_dl).
Cosmetic:
Constify. KNF. Stop open-coding LIST_FOREACH, TAILQ_FOREACH,
et cetera. Use NULL instead of 0 for null pointers. Use
__arraycount(). Reduce gratuitous parenthesization.
Stop using variadic arguments for rip6_output(), it is
unnecessary.
Remove the unnecessary rtentry member rt_genmask and the
code to maintain it, since nothing actually used it.
Make rt_maskedcopy() easier to read by using meaningful variable
names.
Extract a subroutine intern_netmask() for looking up a netmask in
the masks table.
Start converting backslash-ridden IPv6 macros in
sys/netinet6/in6_var.h into inline subroutines that one
can read without special eyeglasses.
One functional change: when the kernel serves an RTM_GET, RTM_LOCK,
or RTM_CHANGE request, it applies the netmask (if supplied) to a
destination before searching for it in the forwarding table.
I have changed sys/netinet/ip_carp.c, carp_setroute(), to remove
the unlawful radix_node knowledge.
Apart from the changes to carp(4), netiso, ATM, and strip(4), I
have run the changes on three nodes in my wireless routing testbed,
which involves IPv4 + IPv6 dynamic routing acrobatics, and it's
working beautifully so far.
2007-07-20 00:48:52 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Definitions of protocols supported in the link-layer domain.
|
|
|
|
*/
|
|
|
|
|
|
|
|
DOMAIN_DEFINE(linkdomain); /* forward define and add to link set */
|
|
|
|
|
2014-05-18 18:46:15 +04:00
|
|
|
static const struct pr_usrreqs link_usrreqs = {
|
2014-05-19 06:51:24 +04:00
|
|
|
.pr_attach = link_attach,
|
|
|
|
.pr_detach = link_detach,
|
2014-07-24 19:12:03 +04:00
|
|
|
.pr_accept = link_accept,
|
|
|
|
.pr_bind = link_bind,
|
|
|
|
.pr_listen = link_listen,
|
2014-07-31 17:21:33 +04:00
|
|
|
.pr_connect = link_connect,
|
2014-08-09 09:33:00 +04:00
|
|
|
.pr_connect2 = link_connect2,
|
split PRU_DISCONNECT, PRU_SHUTDOWN and PRU_ABORT function out of
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-31 07:39:35 +04:00
|
|
|
.pr_disconnect = link_disconnect,
|
|
|
|
.pr_shutdown = link_shutdown,
|
|
|
|
.pr_abort = link_abort,
|
2014-06-22 12:10:18 +04:00
|
|
|
.pr_ioctl = link_ioctl,
|
2014-07-06 20:06:19 +04:00
|
|
|
.pr_stat = link_stat,
|
* split PRU_PEERADDR and PRU_SOCKADDR function out of pr_generic()
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-09 08:54:03 +04:00
|
|
|
.pr_peeraddr = link_peeraddr,
|
|
|
|
.pr_sockaddr = link_sockaddr,
|
2014-08-08 07:05:44 +04:00
|
|
|
.pr_rcvd = link_rcvd,
|
2014-07-31 17:21:33 +04:00
|
|
|
.pr_recvoob = link_recvoob,
|
2014-08-05 11:55:31 +04:00
|
|
|
.pr_send = link_send,
|
2014-07-31 17:21:33 +04:00
|
|
|
.pr_sendoob = link_sendoob,
|
2014-08-09 09:33:00 +04:00
|
|
|
.pr_purgeif = link_purgeif,
|
2014-05-18 18:46:15 +04:00
|
|
|
};
|
|
|
|
|
2008-05-13 22:09:22 +04:00
|
|
|
const struct protosw linksw[] = {
|
|
|
|
{ .pr_type = SOCK_DGRAM,
|
|
|
|
.pr_domain = &linkdomain,
|
|
|
|
.pr_protocol = 0, /* XXX */
|
|
|
|
.pr_flags = PR_ATOMIC|PR_ADDR|PR_PURGEIF,
|
|
|
|
.pr_input = NULL,
|
|
|
|
.pr_ctlinput = NULL,
|
|
|
|
.pr_ctloutput = NULL,
|
2014-05-18 18:46:15 +04:00
|
|
|
.pr_usrreqs = &link_usrreqs,
|
2008-05-13 22:09:22 +04:00
|
|
|
.pr_init = link_init,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
Take steps to hide the radix_node implementation of the forwarding table
from the forwarding table's users:
Introduce rt_walktree() for walking the routing table and
applying a function to each rtentry. Replace most
rn_walktree() calls with it.
Use rt_getkey()/rt_setkey() to get/set a route's destination.
Keep a pointer to the sockaddr key in the rtentry, so that
rtentry users do not have to grovel in the radix_node for
the key.
Add a RTM_GET method to rtrequest. Use that instead of
radix_node lookups in, e.g., carp(4).
Add sys/net/link_proto.c, which supplies sockaddr routines for
link-layer socket addresses (sockaddr_dl).
Cosmetic:
Constify. KNF. Stop open-coding LIST_FOREACH, TAILQ_FOREACH,
et cetera. Use NULL instead of 0 for null pointers. Use
__arraycount(). Reduce gratuitous parenthesization.
Stop using variadic arguments for rip6_output(), it is
unnecessary.
Remove the unnecessary rtentry member rt_genmask and the
code to maintain it, since nothing actually used it.
Make rt_maskedcopy() easier to read by using meaningful variable
names.
Extract a subroutine intern_netmask() for looking up a netmask in
the masks table.
Start converting backslash-ridden IPv6 macros in
sys/netinet6/in6_var.h into inline subroutines that one
can read without special eyeglasses.
One functional change: when the kernel serves an RTM_GET, RTM_LOCK,
or RTM_CHANGE request, it applies the netmask (if supplied) to a
destination before searching for it in the forwarding table.
I have changed sys/netinet/ip_carp.c, carp_setroute(), to remove
the unlawful radix_node knowledge.
Apart from the changes to carp(4), netiso, ATM, and strip(4), I
have run the changes on three nodes in my wireless routing testbed,
which involves IPv4 + IPv6 dynamic routing acrobatics, and it's
working beautifully so far.
2007-07-20 00:48:52 +04:00
|
|
|
struct domain linkdomain = {
|
|
|
|
.dom_family = AF_LINK,
|
|
|
|
.dom_name = "link",
|
|
|
|
.dom_externalize = NULL,
|
|
|
|
.dom_dispose = NULL,
|
2008-05-13 22:09:22 +04:00
|
|
|
.dom_protosw = linksw,
|
|
|
|
.dom_protoswNPROTOSW = &linksw[__arraycount(linksw)],
|
Take steps to hide the radix_node implementation of the forwarding table
from the forwarding table's users:
Introduce rt_walktree() for walking the routing table and
applying a function to each rtentry. Replace most
rn_walktree() calls with it.
Use rt_getkey()/rt_setkey() to get/set a route's destination.
Keep a pointer to the sockaddr key in the rtentry, so that
rtentry users do not have to grovel in the radix_node for
the key.
Add a RTM_GET method to rtrequest. Use that instead of
radix_node lookups in, e.g., carp(4).
Add sys/net/link_proto.c, which supplies sockaddr routines for
link-layer socket addresses (sockaddr_dl).
Cosmetic:
Constify. KNF. Stop open-coding LIST_FOREACH, TAILQ_FOREACH,
et cetera. Use NULL instead of 0 for null pointers. Use
__arraycount(). Reduce gratuitous parenthesization.
Stop using variadic arguments for rip6_output(), it is
unnecessary.
Remove the unnecessary rtentry member rt_genmask and the
code to maintain it, since nothing actually used it.
Make rt_maskedcopy() easier to read by using meaningful variable
names.
Extract a subroutine intern_netmask() for looking up a netmask in
the masks table.
Start converting backslash-ridden IPv6 macros in
sys/netinet6/in6_var.h into inline subroutines that one
can read without special eyeglasses.
One functional change: when the kernel serves an RTM_GET, RTM_LOCK,
or RTM_CHANGE request, it applies the netmask (if supplied) to a
destination before searching for it in the forwarding table.
I have changed sys/netinet/ip_carp.c, carp_setroute(), to remove
the unlawful radix_node knowledge.
Apart from the changes to carp(4), netiso, ATM, and strip(4), I
have run the changes on three nodes in my wireless routing testbed,
which involves IPv4 + IPv6 dynamic routing acrobatics, and it's
working beautifully so far.
2007-07-20 00:48:52 +04:00
|
|
|
.dom_sockaddr_cmp = sockaddr_dl_cmp
|
|
|
|
};
|
|
|
|
|
2008-05-13 22:09:22 +04:00
|
|
|
static void
|
|
|
|
link_init(void)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
link_control(struct socket *so, unsigned long cmd, void *data,
|
2014-07-01 09:49:18 +04:00
|
|
|
struct ifnet *ifp)
|
2008-05-13 22:09:22 +04:00
|
|
|
{
|
|
|
|
int error, s;
|
|
|
|
bool isactive, mkactive;
|
|
|
|
struct if_laddrreq *iflr;
|
|
|
|
union {
|
|
|
|
struct sockaddr sa;
|
|
|
|
struct sockaddr_dl sdl;
|
|
|
|
struct sockaddr_storage ss;
|
|
|
|
} u;
|
|
|
|
struct ifaddr *ifa;
|
|
|
|
const struct sockaddr_dl *asdl, *nsdl;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SIOCALIFADDR:
|
|
|
|
case SIOCDLIFADDR:
|
|
|
|
case SIOCGLIFADDR:
|
|
|
|
iflr = data;
|
|
|
|
|
|
|
|
if (iflr->addr.ss_family != AF_LINK)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
asdl = satocsdl(sstocsa(&iflr->addr));
|
|
|
|
|
|
|
|
if (asdl->sdl_alen != ifp->if_addrlen)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
if (sockaddr_dl_init(&u.sdl, sizeof(u.ss), ifp->if_index,
|
|
|
|
ifp->if_type, ifp->if_xname, strlen(ifp->if_xname),
|
|
|
|
CLLADDR(asdl), asdl->sdl_alen) == NULL)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
if ((iflr->flags & IFLR_PREFIX) == 0)
|
|
|
|
;
|
|
|
|
else if (iflr->prefixlen != NBBY * ifp->if_addrlen)
|
|
|
|
return EINVAL; /* XXX match with prefix */
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
s = splnet();
|
|
|
|
|
|
|
|
IFADDR_FOREACH(ifa, ifp) {
|
|
|
|
if (sockaddr_cmp(&u.sa, ifa->ifa_addr) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SIOCGLIFADDR:
|
|
|
|
if ((iflr->flags & IFLR_PREFIX) == 0) {
|
|
|
|
IFADDR_FOREACH(ifa, ifp) {
|
|
|
|
if (ifa->ifa_addr->sa_family == AF_LINK)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ifa == NULL) {
|
2011-10-07 20:34:31 +04:00
|
|
|
error = EADDRNOTAVAIL;
|
2008-05-13 22:09:22 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ifa == ifp->if_dl)
|
|
|
|
iflr->flags = IFLR_ACTIVE;
|
|
|
|
else
|
|
|
|
iflr->flags = 0;
|
|
|
|
|
*** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.
Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)
Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.
Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.
Return consistent, appropriate error codes from network drivers.
Improve readability. KNF.
*** Details ***
In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.
In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.
Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.
In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.
Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:
switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}
Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,
switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}
unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).
In ipw(4), remove an if_set_sadl() call that is out of place.
In nfe(4), reuse the jumbo MTU logic in ether_ioctl().
Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.
Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.
Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.
Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.
In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.
Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.
In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.
Let ifioctl_common() handle SIOCGIFADDR.
Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.
In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.
bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 03:20:01 +03:00
|
|
|
if (ifa == ifp->if_hwdl)
|
|
|
|
iflr->flags |= IFLR_FACTORY;
|
|
|
|
|
2008-05-13 22:09:22 +04:00
|
|
|
sockaddr_copy(sstosa(&iflr->addr), sizeof(iflr->addr),
|
|
|
|
ifa->ifa_addr);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case SIOCDLIFADDR:
|
|
|
|
if (ifa == NULL)
|
|
|
|
error = EADDRNOTAVAIL;
|
*** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.
Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)
Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.
Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.
Return consistent, appropriate error codes from network drivers.
Improve readability. KNF.
*** Details ***
In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.
In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.
Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.
In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.
Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:
switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}
Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,
switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}
unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).
In ipw(4), remove an if_set_sadl() call that is out of place.
In nfe(4), reuse the jumbo MTU logic in ether_ioctl().
Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.
Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.
Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.
Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.
In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.
Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.
In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.
Let ifioctl_common() handle SIOCGIFADDR.
Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.
In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.
bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 03:20:01 +03:00
|
|
|
else if (ifa == ifp->if_dl || ifa == ifp->if_hwdl)
|
2008-05-13 22:09:22 +04:00
|
|
|
error = EBUSY;
|
|
|
|
else {
|
|
|
|
/* TBD routing socket */
|
|
|
|
rt_newaddrmsg(RTM_DELETE, ifa, 0, NULL);
|
|
|
|
ifa_remove(ifp, ifa);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SIOCALIFADDR:
|
|
|
|
if (ifa != NULL)
|
|
|
|
;
|
|
|
|
else if ((ifa = if_dl_create(ifp, &nsdl)) == NULL) {
|
|
|
|
error = ENOMEM;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
sockaddr_copy(ifa->ifa_addr,
|
|
|
|
ifa->ifa_addr->sa_len, &u.sa);
|
|
|
|
ifa_insert(ifp, ifa);
|
|
|
|
rt_newaddrmsg(RTM_ADD, ifa, 0, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
mkactive = (iflr->flags & IFLR_ACTIVE) != 0;
|
|
|
|
isactive = (ifa == ifp->if_dl);
|
|
|
|
|
|
|
|
if (!isactive && mkactive) {
|
|
|
|
if_activate_sadl(ifp, ifa, nsdl);
|
2010-11-12 19:30:26 +03:00
|
|
|
rt_newaddrmsg(RTM_CHANGE, ifa, 0, NULL);
|
2008-05-13 22:09:22 +04:00
|
|
|
error = ENETRESET;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
if (error != ENETRESET)
|
|
|
|
return error;
|
2014-07-21 16:03:38 +04:00
|
|
|
else if ((ifp->if_flags & IFF_RUNNING) != 0 &&
|
|
|
|
ifp->if_init != NULL)
|
2008-05-13 22:09:22 +04:00
|
|
|
return (*ifp->if_init)(ifp);
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return ENOTTY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-19 06:51:24 +04:00
|
|
|
static int
|
|
|
|
link_attach(struct socket *so, int proto)
|
|
|
|
{
|
|
|
|
sosetlock(so);
|
|
|
|
KASSERT(solocked(so));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
link_detach(struct socket *so)
|
|
|
|
{
|
|
|
|
KASSERT(solocked(so));
|
|
|
|
sofree(so);
|
|
|
|
}
|
|
|
|
|
2014-07-24 19:12:03 +04:00
|
|
|
static int
|
2015-04-25 01:32:37 +03:00
|
|
|
link_accept(struct socket *so, struct sockaddr *nam)
|
2014-07-24 19:12:03 +04:00
|
|
|
{
|
|
|
|
KASSERT(solocked(so));
|
|
|
|
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2015-04-03 23:01:07 +03:00
|
|
|
link_bind(struct socket *so, struct sockaddr *nam, struct lwp *l)
|
2014-07-24 19:12:03 +04:00
|
|
|
{
|
|
|
|
KASSERT(solocked(so));
|
|
|
|
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-08-05 09:24:26 +04:00
|
|
|
link_listen(struct socket *so, struct lwp *l)
|
2014-07-24 19:12:03 +04:00
|
|
|
{
|
|
|
|
KASSERT(solocked(so));
|
|
|
|
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2014-07-31 17:21:33 +04:00
|
|
|
static int
|
2014-08-05 09:24:26 +04:00
|
|
|
link_connect(struct socket *so, struct mbuf *nam, struct lwp *l)
|
2014-07-31 17:21:33 +04:00
|
|
|
{
|
|
|
|
KASSERT(solocked(so));
|
|
|
|
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2014-08-09 09:33:00 +04:00
|
|
|
static int
|
|
|
|
link_connect2(struct socket *so, struct socket *so2)
|
|
|
|
{
|
|
|
|
KASSERT(solocked(so));
|
|
|
|
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
split PRU_DISCONNECT, PRU_SHUTDOWN and PRU_ABORT function out of
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-31 07:39:35 +04:00
|
|
|
static int
|
|
|
|
link_disconnect(struct socket *so)
|
|
|
|
{
|
|
|
|
KASSERT(solocked(so));
|
|
|
|
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
link_shutdown(struct socket *so)
|
|
|
|
{
|
|
|
|
KASSERT(solocked(so));
|
|
|
|
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
link_abort(struct socket *so)
|
|
|
|
{
|
|
|
|
KASSERT(solocked(so));
|
|
|
|
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2014-06-22 12:10:18 +04:00
|
|
|
static int
|
2014-07-01 09:49:18 +04:00
|
|
|
link_ioctl(struct socket *so, u_long cmd, void *nam, struct ifnet *ifp)
|
2014-06-22 12:10:18 +04:00
|
|
|
{
|
2014-07-01 09:49:18 +04:00
|
|
|
return link_control(so, cmd, nam, ifp);
|
2014-06-22 12:10:18 +04:00
|
|
|
}
|
|
|
|
|
2014-07-06 20:06:19 +04:00
|
|
|
static int
|
|
|
|
link_stat(struct socket *so, struct stat *ub)
|
|
|
|
{
|
2014-07-07 21:13:56 +04:00
|
|
|
KASSERT(solocked(so));
|
|
|
|
|
2014-07-06 20:06:19 +04:00
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
* split PRU_PEERADDR and PRU_SOCKADDR function out of pr_generic()
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-09 08:54:03 +04:00
|
|
|
static int
|
2015-04-25 01:32:37 +03:00
|
|
|
link_peeraddr(struct socket *so, struct sockaddr *nam)
|
* split PRU_PEERADDR and PRU_SOCKADDR function out of pr_generic()
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-09 08:54:03 +04:00
|
|
|
{
|
|
|
|
KASSERT(solocked(so));
|
|
|
|
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2015-04-25 01:32:37 +03:00
|
|
|
link_sockaddr(struct socket *so, struct sockaddr *nam)
|
* split PRU_PEERADDR and PRU_SOCKADDR function out of pr_generic()
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-09 08:54:03 +04:00
|
|
|
{
|
|
|
|
KASSERT(solocked(so));
|
|
|
|
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2014-08-08 07:05:44 +04:00
|
|
|
static int
|
|
|
|
link_rcvd(struct socket *so, int flags, struct lwp *l)
|
|
|
|
{
|
|
|
|
KASSERT(solocked(so));
|
|
|
|
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2014-07-31 17:21:33 +04:00
|
|
|
static int
|
|
|
|
link_recvoob(struct socket *so, struct mbuf *m, int flags)
|
|
|
|
{
|
|
|
|
KASSERT(solocked(so));
|
|
|
|
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2014-08-05 11:55:31 +04:00
|
|
|
static int
|
|
|
|
link_send(struct socket *so, struct mbuf *m, struct mbuf *nam,
|
|
|
|
struct mbuf *control, struct lwp *l)
|
|
|
|
{
|
|
|
|
KASSERT(solocked(so));
|
|
|
|
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2014-07-31 17:21:33 +04:00
|
|
|
static int
|
|
|
|
link_sendoob(struct socket *so, struct mbuf *m, struct mbuf *control)
|
|
|
|
{
|
|
|
|
KASSERT(solocked(so));
|
|
|
|
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2014-08-09 09:33:00 +04:00
|
|
|
static int
|
|
|
|
link_purgeif(struct socket *so, struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
Take steps to hide the radix_node implementation of the forwarding table
from the forwarding table's users:
Introduce rt_walktree() for walking the routing table and
applying a function to each rtentry. Replace most
rn_walktree() calls with it.
Use rt_getkey()/rt_setkey() to get/set a route's destination.
Keep a pointer to the sockaddr key in the rtentry, so that
rtentry users do not have to grovel in the radix_node for
the key.
Add a RTM_GET method to rtrequest. Use that instead of
radix_node lookups in, e.g., carp(4).
Add sys/net/link_proto.c, which supplies sockaddr routines for
link-layer socket addresses (sockaddr_dl).
Cosmetic:
Constify. KNF. Stop open-coding LIST_FOREACH, TAILQ_FOREACH,
et cetera. Use NULL instead of 0 for null pointers. Use
__arraycount(). Reduce gratuitous parenthesization.
Stop using variadic arguments for rip6_output(), it is
unnecessary.
Remove the unnecessary rtentry member rt_genmask and the
code to maintain it, since nothing actually used it.
Make rt_maskedcopy() easier to read by using meaningful variable
names.
Extract a subroutine intern_netmask() for looking up a netmask in
the masks table.
Start converting backslash-ridden IPv6 macros in
sys/netinet6/in6_var.h into inline subroutines that one
can read without special eyeglasses.
One functional change: when the kernel serves an RTM_GET, RTM_LOCK,
or RTM_CHANGE request, it applies the netmask (if supplied) to a
destination before searching for it in the forwarding table.
I have changed sys/netinet/ip_carp.c, carp_setroute(), to remove
the unlawful radix_node knowledge.
Apart from the changes to carp(4), netiso, ATM, and strip(4), I
have run the changes on three nodes in my wireless routing testbed,
which involves IPv4 + IPv6 dynamic routing acrobatics, and it's
working beautifully so far.
2007-07-20 00:48:52 +04:00
|
|
|
/* Compare the field at byte offsets [fieldstart, fieldend) in
|
|
|
|
* two memory regions, [l, l + llen) and [r, r + llen).
|
|
|
|
*/
|
|
|
|
static inline int
|
|
|
|
submemcmp(const void *l, const void *r,
|
|
|
|
const uint_fast8_t llen, const uint_fast8_t rlen,
|
|
|
|
const uint_fast8_t fieldstart, const uint_fast8_t fieldend)
|
|
|
|
{
|
|
|
|
uint_fast8_t cmpend, minlen;
|
|
|
|
const uint8_t *lb = l, *rb = r;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
minlen = MIN(llen, rlen);
|
|
|
|
|
|
|
|
/* The field is missing from one region. The shorter region is the
|
|
|
|
* lesser region.
|
|
|
|
*/
|
|
|
|
if (fieldstart >= minlen)
|
|
|
|
return llen - rlen;
|
|
|
|
|
|
|
|
/* Two empty, present fields are always equal. */
|
|
|
|
if (fieldstart > fieldend)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cmpend = MIN(fieldend, minlen);
|
|
|
|
|
|
|
|
rc = memcmp(&lb[fieldstart], &rb[fieldstart], cmpend - fieldstart);
|
|
|
|
|
|
|
|
if (rc != 0)
|
|
|
|
return rc;
|
|
|
|
/* If one or both fields are truncated, then the shorter is the lesser
|
|
|
|
* field.
|
|
|
|
*/
|
|
|
|
if (minlen < fieldend)
|
|
|
|
return llen - rlen;
|
|
|
|
/* Fields are full-length and equal. The fields are equal. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-08-07 08:06:20 +04:00
|
|
|
uint8_t
|
|
|
|
sockaddr_dl_measure(uint8_t namelen, uint8_t addrlen)
|
|
|
|
{
|
|
|
|
return offsetof(struct sockaddr_dl, sdl_data[namelen + addrlen]);
|
|
|
|
}
|
|
|
|
|
Use malloc(9) for sockaddrs instead of pool(9), and remove dom_sa_pool
and dom_sa_len members from struct domain. Pools of fixed-size
objects are too rigid for sockaddr_dls, whose size can vary over
a wide range.
Return sockaddr_dl to its "historical" size. Now that I'm using
malloc(9) instead of pool(9) to allocate sockaddr_dl, I can create
a sockaddr_dl of any size in the kernel, so expanding sockaddr_dl
is useless.
Avoid using sizeof(struct sockaddr_dl) in the kernel.
Introduce sockaddr_dl_alloc() for allocating & initializing an
arbitrary sockaddr_dl on the heap.
Add an argument, the sockaddr length, to sockaddr_alloc(),
sockaddr_copy(), and sockaddr_dl_setaddr().
Constify: LLADDR() -> CLLADDR().
Where the kernel overwrites LLADDR(), use sockaddr_dl_setaddr(),
instead. Used properly, sockaddr_dl_setaddr() will not overrun
the end of the sockaddr.
2007-08-30 06:17:34 +04:00
|
|
|
struct sockaddr *
|
|
|
|
sockaddr_dl_alloc(uint16_t ifindex, uint8_t type,
|
|
|
|
const void *name, uint8_t namelen, const void *addr, uint8_t addrlen,
|
|
|
|
int flags)
|
2007-08-07 08:06:20 +04:00
|
|
|
{
|
Use malloc(9) for sockaddrs instead of pool(9), and remove dom_sa_pool
and dom_sa_len members from struct domain. Pools of fixed-size
objects are too rigid for sockaddr_dls, whose size can vary over
a wide range.
Return sockaddr_dl to its "historical" size. Now that I'm using
malloc(9) instead of pool(9) to allocate sockaddr_dl, I can create
a sockaddr_dl of any size in the kernel, so expanding sockaddr_dl
is useless.
Avoid using sizeof(struct sockaddr_dl) in the kernel.
Introduce sockaddr_dl_alloc() for allocating & initializing an
arbitrary sockaddr_dl on the heap.
Add an argument, the sockaddr length, to sockaddr_alloc(),
sockaddr_copy(), and sockaddr_dl_setaddr().
Constify: LLADDR() -> CLLADDR().
Where the kernel overwrites LLADDR(), use sockaddr_dl_setaddr(),
instead. Used properly, sockaddr_dl_setaddr() will not overrun
the end of the sockaddr.
2007-08-30 06:17:34 +04:00
|
|
|
struct sockaddr *sa;
|
|
|
|
socklen_t len;
|
|
|
|
|
|
|
|
len = sockaddr_dl_measure(namelen, addrlen);
|
|
|
|
sa = sockaddr_alloc(AF_LINK, len, flags);
|
|
|
|
|
|
|
|
if (sa == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (sockaddr_dl_init(satosdl(sa), len, ifindex, type, name, namelen,
|
|
|
|
addr, addrlen) == NULL) {
|
|
|
|
sockaddr_free(sa);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sa;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct sockaddr_dl *
|
|
|
|
sockaddr_dl_init(struct sockaddr_dl *sdl, socklen_t socklen, uint16_t ifindex,
|
|
|
|
uint8_t type, const void *name, uint8_t namelen, const void *addr,
|
|
|
|
uint8_t addrlen)
|
|
|
|
{
|
|
|
|
socklen_t len;
|
|
|
|
|
2007-08-07 08:06:20 +04:00
|
|
|
sdl->sdl_family = AF_LINK;
|
|
|
|
sdl->sdl_slen = 0;
|
Use malloc(9) for sockaddrs instead of pool(9), and remove dom_sa_pool
and dom_sa_len members from struct domain. Pools of fixed-size
objects are too rigid for sockaddr_dls, whose size can vary over
a wide range.
Return sockaddr_dl to its "historical" size. Now that I'm using
malloc(9) instead of pool(9) to allocate sockaddr_dl, I can create
a sockaddr_dl of any size in the kernel, so expanding sockaddr_dl
is useless.
Avoid using sizeof(struct sockaddr_dl) in the kernel.
Introduce sockaddr_dl_alloc() for allocating & initializing an
arbitrary sockaddr_dl on the heap.
Add an argument, the sockaddr length, to sockaddr_alloc(),
sockaddr_copy(), and sockaddr_dl_setaddr().
Constify: LLADDR() -> CLLADDR().
Where the kernel overwrites LLADDR(), use sockaddr_dl_setaddr(),
instead. Used properly, sockaddr_dl_setaddr() will not overrun
the end of the sockaddr.
2007-08-30 06:17:34 +04:00
|
|
|
len = sockaddr_dl_measure(namelen, addrlen);
|
|
|
|
if (len > socklen) {
|
|
|
|
sdl->sdl_len = socklen;
|
|
|
|
#ifdef DIAGNOSTIC
|
2014-07-16 00:17:53 +04:00
|
|
|
printf("%s: too long: %u > %u\n", __func__, (u_int)len,
|
|
|
|
(u_int)socklen);
|
Use malloc(9) for sockaddrs instead of pool(9), and remove dom_sa_pool
and dom_sa_len members from struct domain. Pools of fixed-size
objects are too rigid for sockaddr_dls, whose size can vary over
a wide range.
Return sockaddr_dl to its "historical" size. Now that I'm using
malloc(9) instead of pool(9) to allocate sockaddr_dl, I can create
a sockaddr_dl of any size in the kernel, so expanding sockaddr_dl
is useless.
Avoid using sizeof(struct sockaddr_dl) in the kernel.
Introduce sockaddr_dl_alloc() for allocating & initializing an
arbitrary sockaddr_dl on the heap.
Add an argument, the sockaddr length, to sockaddr_alloc(),
sockaddr_copy(), and sockaddr_dl_setaddr().
Constify: LLADDR() -> CLLADDR().
Where the kernel overwrites LLADDR(), use sockaddr_dl_setaddr(),
instead. Used properly, sockaddr_dl_setaddr() will not overrun
the end of the sockaddr.
2007-08-30 06:17:34 +04:00
|
|
|
#endif
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
sdl->sdl_len = len;
|
2007-08-07 08:06:20 +04:00
|
|
|
sdl->sdl_index = ifindex;
|
|
|
|
sdl->sdl_type = type;
|
Use malloc(9) for sockaddrs instead of pool(9), and remove dom_sa_pool
and dom_sa_len members from struct domain. Pools of fixed-size
objects are too rigid for sockaddr_dls, whose size can vary over
a wide range.
Return sockaddr_dl to its "historical" size. Now that I'm using
malloc(9) instead of pool(9) to allocate sockaddr_dl, I can create
a sockaddr_dl of any size in the kernel, so expanding sockaddr_dl
is useless.
Avoid using sizeof(struct sockaddr_dl) in the kernel.
Introduce sockaddr_dl_alloc() for allocating & initializing an
arbitrary sockaddr_dl on the heap.
Add an argument, the sockaddr length, to sockaddr_alloc(),
sockaddr_copy(), and sockaddr_dl_setaddr().
Constify: LLADDR() -> CLLADDR().
Where the kernel overwrites LLADDR(), use sockaddr_dl_setaddr(),
instead. Used properly, sockaddr_dl_setaddr() will not overrun
the end of the sockaddr.
2007-08-30 06:17:34 +04:00
|
|
|
memset(&sdl->sdl_data[0], 0, namelen + addrlen);
|
|
|
|
if (name != NULL) {
|
2007-08-07 08:06:20 +04:00
|
|
|
memcpy(&sdl->sdl_data[0], name, namelen);
|
Use malloc(9) for sockaddrs instead of pool(9), and remove dom_sa_pool
and dom_sa_len members from struct domain. Pools of fixed-size
objects are too rigid for sockaddr_dls, whose size can vary over
a wide range.
Return sockaddr_dl to its "historical" size. Now that I'm using
malloc(9) instead of pool(9) to allocate sockaddr_dl, I can create
a sockaddr_dl of any size in the kernel, so expanding sockaddr_dl
is useless.
Avoid using sizeof(struct sockaddr_dl) in the kernel.
Introduce sockaddr_dl_alloc() for allocating & initializing an
arbitrary sockaddr_dl on the heap.
Add an argument, the sockaddr length, to sockaddr_alloc(),
sockaddr_copy(), and sockaddr_dl_setaddr().
Constify: LLADDR() -> CLLADDR().
Where the kernel overwrites LLADDR(), use sockaddr_dl_setaddr(),
instead. Used properly, sockaddr_dl_setaddr() will not overrun
the end of the sockaddr.
2007-08-30 06:17:34 +04:00
|
|
|
sdl->sdl_nlen = namelen;
|
|
|
|
} else
|
|
|
|
sdl->sdl_nlen = 0;
|
|
|
|
if (addr != NULL) {
|
2007-08-07 08:06:20 +04:00
|
|
|
memcpy(&sdl->sdl_data[sdl->sdl_nlen], addr, addrlen);
|
Use malloc(9) for sockaddrs instead of pool(9), and remove dom_sa_pool
and dom_sa_len members from struct domain. Pools of fixed-size
objects are too rigid for sockaddr_dls, whose size can vary over
a wide range.
Return sockaddr_dl to its "historical" size. Now that I'm using
malloc(9) instead of pool(9) to allocate sockaddr_dl, I can create
a sockaddr_dl of any size in the kernel, so expanding sockaddr_dl
is useless.
Avoid using sizeof(struct sockaddr_dl) in the kernel.
Introduce sockaddr_dl_alloc() for allocating & initializing an
arbitrary sockaddr_dl on the heap.
Add an argument, the sockaddr length, to sockaddr_alloc(),
sockaddr_copy(), and sockaddr_dl_setaddr().
Constify: LLADDR() -> CLLADDR().
Where the kernel overwrites LLADDR(), use sockaddr_dl_setaddr(),
instead. Used properly, sockaddr_dl_setaddr() will not overrun
the end of the sockaddr.
2007-08-30 06:17:34 +04:00
|
|
|
sdl->sdl_alen = addrlen;
|
|
|
|
} else
|
|
|
|
sdl->sdl_alen = 0;
|
|
|
|
return sdl;
|
2007-08-07 08:06:20 +04:00
|
|
|
}
|
|
|
|
|
Take steps to hide the radix_node implementation of the forwarding table
from the forwarding table's users:
Introduce rt_walktree() for walking the routing table and
applying a function to each rtentry. Replace most
rn_walktree() calls with it.
Use rt_getkey()/rt_setkey() to get/set a route's destination.
Keep a pointer to the sockaddr key in the rtentry, so that
rtentry users do not have to grovel in the radix_node for
the key.
Add a RTM_GET method to rtrequest. Use that instead of
radix_node lookups in, e.g., carp(4).
Add sys/net/link_proto.c, which supplies sockaddr routines for
link-layer socket addresses (sockaddr_dl).
Cosmetic:
Constify. KNF. Stop open-coding LIST_FOREACH, TAILQ_FOREACH,
et cetera. Use NULL instead of 0 for null pointers. Use
__arraycount(). Reduce gratuitous parenthesization.
Stop using variadic arguments for rip6_output(), it is
unnecessary.
Remove the unnecessary rtentry member rt_genmask and the
code to maintain it, since nothing actually used it.
Make rt_maskedcopy() easier to read by using meaningful variable
names.
Extract a subroutine intern_netmask() for looking up a netmask in
the masks table.
Start converting backslash-ridden IPv6 macros in
sys/netinet6/in6_var.h into inline subroutines that one
can read without special eyeglasses.
One functional change: when the kernel serves an RTM_GET, RTM_LOCK,
or RTM_CHANGE request, it applies the netmask (if supplied) to a
destination before searching for it in the forwarding table.
I have changed sys/netinet/ip_carp.c, carp_setroute(), to remove
the unlawful radix_node knowledge.
Apart from the changes to carp(4), netiso, ATM, and strip(4), I
have run the changes on three nodes in my wireless routing testbed,
which involves IPv4 + IPv6 dynamic routing acrobatics, and it's
working beautifully so far.
2007-07-20 00:48:52 +04:00
|
|
|
static int
|
|
|
|
sockaddr_dl_cmp(const struct sockaddr *sa1, const struct sockaddr *sa2)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
const uint_fast8_t indexofs = offsetof(struct sockaddr_dl, sdl_index);
|
|
|
|
const uint_fast8_t nlenofs = offsetof(struct sockaddr_dl, sdl_nlen);
|
|
|
|
uint_fast8_t dataofs = offsetof(struct sockaddr_dl, sdl_data[0]);
|
|
|
|
const struct sockaddr_dl *sdl1, *sdl2;
|
|
|
|
|
|
|
|
sdl1 = satocsdl(sa1);
|
|
|
|
sdl2 = satocsdl(sa2);
|
|
|
|
|
|
|
|
rc = submemcmp(sdl1, sdl2, sdl1->sdl_len, sdl2->sdl_len,
|
|
|
|
indexofs, nlenofs);
|
|
|
|
|
|
|
|
if (rc != 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
rc = submemcmp(sdl1, sdl2, sdl1->sdl_len, sdl2->sdl_len,
|
|
|
|
dataofs, dataofs + MIN(sdl1->sdl_nlen, sdl2->sdl_nlen));
|
|
|
|
|
|
|
|
if (rc != 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
if (sdl1->sdl_nlen != sdl2->sdl_nlen)
|
|
|
|
return sdl1->sdl_nlen - sdl2->sdl_nlen;
|
|
|
|
|
|
|
|
dataofs += sdl1->sdl_nlen;
|
|
|
|
|
|
|
|
rc = submemcmp(sdl1, sdl2, sdl1->sdl_len, sdl2->sdl_len,
|
|
|
|
dataofs, dataofs + MIN(sdl1->sdl_alen, sdl2->sdl_alen));
|
|
|
|
|
|
|
|
if (rc != 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
if (sdl1->sdl_alen != sdl2->sdl_alen)
|
|
|
|
return sdl1->sdl_alen - sdl2->sdl_alen;
|
|
|
|
|
|
|
|
dataofs += sdl1->sdl_alen;
|
|
|
|
|
|
|
|
rc = submemcmp(sdl1, sdl2, sdl1->sdl_len, sdl2->sdl_len,
|
|
|
|
dataofs, dataofs + MIN(sdl1->sdl_slen, sdl2->sdl_slen));
|
|
|
|
|
|
|
|
if (sdl1->sdl_slen != sdl2->sdl_slen)
|
|
|
|
return sdl1->sdl_slen - sdl2->sdl_slen;
|
|
|
|
|
|
|
|
return sdl1->sdl_len - sdl2->sdl_len;
|
|
|
|
}
|
2007-08-07 08:06:20 +04:00
|
|
|
|
|
|
|
struct sockaddr_dl *
|
Use malloc(9) for sockaddrs instead of pool(9), and remove dom_sa_pool
and dom_sa_len members from struct domain. Pools of fixed-size
objects are too rigid for sockaddr_dls, whose size can vary over
a wide range.
Return sockaddr_dl to its "historical" size. Now that I'm using
malloc(9) instead of pool(9) to allocate sockaddr_dl, I can create
a sockaddr_dl of any size in the kernel, so expanding sockaddr_dl
is useless.
Avoid using sizeof(struct sockaddr_dl) in the kernel.
Introduce sockaddr_dl_alloc() for allocating & initializing an
arbitrary sockaddr_dl on the heap.
Add an argument, the sockaddr length, to sockaddr_alloc(),
sockaddr_copy(), and sockaddr_dl_setaddr().
Constify: LLADDR() -> CLLADDR().
Where the kernel overwrites LLADDR(), use sockaddr_dl_setaddr(),
instead. Used properly, sockaddr_dl_setaddr() will not overrun
the end of the sockaddr.
2007-08-30 06:17:34 +04:00
|
|
|
sockaddr_dl_setaddr(struct sockaddr_dl *sdl, socklen_t socklen,
|
|
|
|
const void *addr, uint8_t addrlen)
|
2007-08-07 08:06:20 +04:00
|
|
|
{
|
Use malloc(9) for sockaddrs instead of pool(9), and remove dom_sa_pool
and dom_sa_len members from struct domain. Pools of fixed-size
objects are too rigid for sockaddr_dls, whose size can vary over
a wide range.
Return sockaddr_dl to its "historical" size. Now that I'm using
malloc(9) instead of pool(9) to allocate sockaddr_dl, I can create
a sockaddr_dl of any size in the kernel, so expanding sockaddr_dl
is useless.
Avoid using sizeof(struct sockaddr_dl) in the kernel.
Introduce sockaddr_dl_alloc() for allocating & initializing an
arbitrary sockaddr_dl on the heap.
Add an argument, the sockaddr length, to sockaddr_alloc(),
sockaddr_copy(), and sockaddr_dl_setaddr().
Constify: LLADDR() -> CLLADDR().
Where the kernel overwrites LLADDR(), use sockaddr_dl_setaddr(),
instead. Used properly, sockaddr_dl_setaddr() will not overrun
the end of the sockaddr.
2007-08-30 06:17:34 +04:00
|
|
|
socklen_t len;
|
|
|
|
|
|
|
|
len = sockaddr_dl_measure(sdl->sdl_nlen, addrlen);
|
|
|
|
if (len > socklen) {
|
|
|
|
#ifdef DIAGNOSTIC
|
2014-07-16 00:17:53 +04:00
|
|
|
printf("%s: too long: %u > %u\n", __func__, (u_int)len,
|
|
|
|
(u_int)socklen);
|
Use malloc(9) for sockaddrs instead of pool(9), and remove dom_sa_pool
and dom_sa_len members from struct domain. Pools of fixed-size
objects are too rigid for sockaddr_dls, whose size can vary over
a wide range.
Return sockaddr_dl to its "historical" size. Now that I'm using
malloc(9) instead of pool(9) to allocate sockaddr_dl, I can create
a sockaddr_dl of any size in the kernel, so expanding sockaddr_dl
is useless.
Avoid using sizeof(struct sockaddr_dl) in the kernel.
Introduce sockaddr_dl_alloc() for allocating & initializing an
arbitrary sockaddr_dl on the heap.
Add an argument, the sockaddr length, to sockaddr_alloc(),
sockaddr_copy(), and sockaddr_dl_setaddr().
Constify: LLADDR() -> CLLADDR().
Where the kernel overwrites LLADDR(), use sockaddr_dl_setaddr(),
instead. Used properly, sockaddr_dl_setaddr() will not overrun
the end of the sockaddr.
2007-08-30 06:17:34 +04:00
|
|
|
#endif
|
2007-08-07 08:06:20 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
memcpy(&sdl->sdl_data[sdl->sdl_nlen], addr, addrlen);
|
|
|
|
sdl->sdl_alen = addrlen;
|
Use malloc(9) for sockaddrs instead of pool(9), and remove dom_sa_pool
and dom_sa_len members from struct domain. Pools of fixed-size
objects are too rigid for sockaddr_dls, whose size can vary over
a wide range.
Return sockaddr_dl to its "historical" size. Now that I'm using
malloc(9) instead of pool(9) to allocate sockaddr_dl, I can create
a sockaddr_dl of any size in the kernel, so expanding sockaddr_dl
is useless.
Avoid using sizeof(struct sockaddr_dl) in the kernel.
Introduce sockaddr_dl_alloc() for allocating & initializing an
arbitrary sockaddr_dl on the heap.
Add an argument, the sockaddr length, to sockaddr_alloc(),
sockaddr_copy(), and sockaddr_dl_setaddr().
Constify: LLADDR() -> CLLADDR().
Where the kernel overwrites LLADDR(), use sockaddr_dl_setaddr(),
instead. Used properly, sockaddr_dl_setaddr() will not overrun
the end of the sockaddr.
2007-08-30 06:17:34 +04:00
|
|
|
sdl->sdl_len = len;
|
2007-08-07 08:06:20 +04:00
|
|
|
return sdl;
|
|
|
|
}
|