NetBSD/sys/netiso/iso.c

989 lines
24 KiB
C
Raw Normal View History

/* $NetBSD: iso.c,v 1.57 2009/08/07 14:04:34 wiz Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
/*-
* Copyright (c) 1991, 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.
*
1998-03-01 05:20:01 +03:00
* @(#)iso.c 8.3 (Berkeley) 1/9/95
*/
/***********************************************************
Copyright IBM Corporation 1987
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of IBM not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
******************************************************************/
/*
* ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
*/
/*
* iso.c: miscellaneous routines to support the iso address family
*/
2001-11-13 03:56:55 +03:00
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: iso.c,v 1.57 2009/08/07 14:04:34 wiz Exp $");
2001-11-13 03:56:55 +03:00
1993-12-18 03:40:47 +03:00
#include <sys/param.h>
#include <sys/systm.h>
1993-12-18 03:40:47 +03:00
#include <sys/ioctl.h>
#include <sys/mbuf.h>
#include <sys/domain.h>
#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/errno.h>
#include <sys/proc.h>
2006-05-15 01:19:33 +04:00
#include <sys/kauth.h>
1993-12-18 03:40:47 +03:00
#include <net/if.h>
#include <net/if_types.h>
1993-12-18 03:40:47 +03:00
#include <net/route.h>
#include <netiso/iso.h>
#include <netiso/iso_var.h>
#include <netiso/iso_snpac.h>
#include <netiso/iso_pcb.h>
#include <netiso/clnp.h>
#include <netiso/argo_debug.h>
1998-07-05 08:37:35 +04:00
#include "opt_iso.h"
#ifdef ISO
int iso_interfaces = 0; /* number of external interfaces */
/*
* FUNCTION: iso_addrmatch1
*
* PURPOSE: decide if the two iso_addrs passed are equal
*
* RETURNS: true if the addrs match, false if they do not
*
* SIDE EFFECTS:
*
* NOTES:
*/
int
iso_addrmatch1(const struct iso_addr *isoaa, const struct iso_addr *isoab)
{
u_int compare_len;
#ifdef ARGO_DEBUG
if (argo_debug[D_ROUTE]) {
1996-10-13 06:03:00 +04:00
printf("iso_addrmatch1: comparing lengths: %d to %d\n", isoaa->isoa_len,
1996-10-11 03:12:43 +04:00
isoab->isoa_len);
1996-10-13 06:03:00 +04:00
printf("a:\n");
dump_buf(isoaa->isoa_genaddr, isoaa->isoa_len);
1996-10-13 06:03:00 +04:00
printf("b:\n");
dump_buf(isoab->isoa_genaddr, isoab->isoa_len);
}
#endif
if ((compare_len = isoaa->isoa_len) != isoab->isoa_len) {
#ifdef ARGO_DEBUG
if (argo_debug[D_ROUTE]) {
1996-10-13 06:03:00 +04:00
printf("iso_addrmatch1: returning false because of lengths\n");
}
#endif
return 0;
}
#ifdef notdef
/* TODO : generalize this to all afis with masks */
if (isoaa->isoa_afi == AFI_37) {
/*
* must not compare 2 least significant digits, or for that
* matter, the DSP
*/
compare_len = ADDR37_IDI_LEN - 1;
}
#endif
#ifdef ARGO_DEBUG
if (argo_debug[D_ROUTE]) {
int i;
const char *a, *b;
a = isoaa->isoa_genaddr;
b = isoab->isoa_genaddr;
for (i = 0; i < compare_len; i++) {
1996-10-13 06:03:00 +04:00
printf("<%x=%x>", a[i] & 0xff, b[i] & 0xff);
if (a[i] != b[i]) {
1996-10-13 06:03:00 +04:00
printf("\naddrs are not equal at byte %d\n", i);
return (0);
}
}
1996-10-13 06:03:00 +04:00
printf("\n");
printf("addrs are equal\n");
return (1);
}
#endif
2009-03-18 18:14:29 +03:00
return (!memcmp(isoaa->isoa_genaddr, isoab->isoa_genaddr, compare_len));
}
/*
* FUNCTION: iso_addrmatch
*
* PURPOSE: decide if the two sockadrr_isos passed are equal
*
* RETURNS: true if the addrs match, false if they do not
*
* SIDE EFFECTS:
*
* NOTES:
*/
int
iso_addrmatch(const struct sockaddr_iso *sisoa,
const struct sockaddr_iso *sisob)
{
return (iso_addrmatch1(&sisoa->siso_addr, &sisob->siso_addr));
}
#ifdef notdef
/*
* FUNCTION: iso_netmatch
*
* PURPOSE: similar to iso_addrmatch but takes sockaddr_iso
* as argument.
*
* RETURNS: true if same net, false if not
*
* SIDE EFFECTS:
*
* NOTES:
*/
int
iso_netmatch(const struct sockaddr_iso *sisoa,
const struct sockaddr_iso *sisob)
{
u_char bufa[sizeof(struct sockaddr_iso)];
u_char bufb[sizeof(struct sockaddr_iso)];
2000-03-30 16:51:13 +04:00
int lena, lenb;
lena = iso_netof(&sisoa->siso_addr, bufa);
lenb = iso_netof(&sisob->siso_addr, bufb);
#ifdef ARGO_DEBUG
if (argo_debug[D_ROUTE]) {
1996-10-13 06:03:00 +04:00
printf("iso_netmatch: comparing lengths: %d to %d\n", lena, lenb);
printf("a:\n");
dump_buf(bufa, lena);
1996-10-13 06:03:00 +04:00
printf("b:\n");
dump_buf(bufb, lenb);
}
#endif
2009-03-18 18:14:29 +03:00
return ((lena == lenb) && (!memcmp(bufa, bufb, lena)));
}
#endif /* notdef */
/*
* FUNCTION: iso_hashchar
*
* PURPOSE: Hash all character in the buffer specified into
* a long. Return the long.
*
* RETURNS: The hash value.
*
* SIDE EFFECTS:
*
* NOTES: The hash is achieved by exclusive ORing 4 byte
* quantities.
*/
u_long
iso_hashchar(void *bufv, int len)
{
char *buf = bufv;
2000-03-30 16:51:13 +04:00
u_long h = 0;
int i;
for (i = 0; i < len; i += 4) {
2000-03-30 16:51:13 +04:00
u_long l = 0;
if ((len - i) < 4) {
/* buffer not multiple of 4 */
switch (len - i) {
case 3:
l |= buf[i + 2] << 8;
case 2:
l |= buf[i + 1] << 16;
case 1:
l |= buf[i] << 24;
break;
default:
1996-10-13 06:03:00 +04:00
printf("iso_hashchar: unexpected value x%x\n", len - i);
break;
}
} else {
l |= buf[i] << 24;
l |= buf[i + 1] << 16;
l |= buf[i + 2] << 8;
l |= buf[i + 3];
}
h ^= l;
}
h ^= (u_long) (len % 4);
return (h);
}
#ifdef notdef
/*
* FUNCTION: iso_hash
*
* PURPOSE: Fill in fields of afhash structure based upon addr
* passed.
*
* RETURNS: none
*
* SIDE EFFECTS:
*
* NOTES:
*/
void
iso_hash(
struct sockaddr_iso *siso, /* address to perform hash on */
struct afhash *hp) /* RETURN: hash info here */
{
u_long buf[sizeof(struct sockaddr_iso) / 4 + 1];
2000-03-30 16:51:13 +04:00
int bufsize;
2009-03-18 19:00:08 +03:00
memset(buf, 0, sizeof(buf));
bufsize = iso_netof(&siso->siso_addr, buf);
hp->afh_nethash = iso_hashchar((void *) buf, bufsize);
#ifdef ARGO_DEBUG
if (argo_debug[D_ROUTE]) {
1996-10-13 06:03:00 +04:00
printf("iso_hash: iso_netof: bufsize = %d\n", bufsize);
}
#endif
hp->afh_hosthash = iso_hashchar((void *) & siso->siso_addr,
siso->siso_addr.isoa_len);
#ifdef ARGO_DEBUG
if (argo_debug[D_ROUTE]) {
1996-10-13 06:03:00 +04:00
printf("iso_hash: %s: nethash = x%x, hosthash = x%x\n",
1996-10-11 03:12:43 +04:00
clnp_iso_addrp(&siso->siso_addr), hp->afh_nethash,
hp->afh_hosthash);
}
#endif
}
/*
* FUNCTION: iso_netof
*
* PURPOSE: Extract the network portion of the iso address.
* The network portion of the iso address varies depending
* on the type of address. The network portion of the
* address will include the IDP. The network portion is:
*
* TYPE DESC
* t37 The AFI and x.121 (IDI)
* osinet The AFI, orgid, snetid
* rfc986 The AFI, vers and network part
* of internet address.
*
* RETURNS: number of bytes placed into buf.
*
* SIDE EFFECTS:
*
* NOTES: Buf is assumed to be big enough
*/
u_int
iso_netof(
struct iso_addr *isoa, /* address */
void * buf) /* RESULT: network portion of address here */
{
u_int len = 1;/* length of afi */
switch (isoa->isoa_afi) {
case AFI_37:
/*
* Due to classic x.25 tunnel vision, there is no
* net portion of an x.121 address. For our purposes
* the AFI will do, so that all x.25 -type addresses
* map to the single x.25 SNPA. (Cannot have more than
* one, obviously).
*/
break;
/* case AFI_OSINET: */
case AFI_RFC986:{
u_short idi; /* value of idi */
/* osinet and rfc986 have idi in the same place */
CTOH(isoa->rfc986_idi[0], isoa->rfc986_idi[1], idi);
if (idi == IDI_OSINET)
/*
* Network portion of OSINET address can only
* be the IDI. Clearly, with one x25 interface,
* one could get to several orgids, and
* several snetids.
*/
#if 0
len += (ADDROSINET_IDI_LEN +
OVLOSINET_ORGID_LEN +
OVLOSINET_SNETID_LEN);
#endif
len += ADDROSINET_IDI_LEN;
else if (idi == IDI_RFC986) {
struct ovl_rfc986 *o986 =
(struct ovl_rfc986 *) isoa;
/*
* bump len to include idi and version (1
* byte)
*/
len += ADDRRFC986_IDI_LEN + 1;
#ifdef ARGO_DEBUG
if (argo_debug[D_ROUTE]) {
1996-10-13 06:03:00 +04:00
printf("iso_netof: isoa ");
dump_buf(isoa, sizeof(*isoa));
1996-10-13 06:03:00 +04:00
printf("iso_netof: inetaddr 0x%x ",
1996-10-11 03:12:43 +04:00
inetaddr);
}
#endif
/*
* bump len by size of network portion of
* inet address
*/
if (IN_CLASSA(o986->o986_inetaddr)) {
len += 4 - IN_CLASSA_NSHIFT / 8;
#ifdef ARGO_DEBUG
if (argo_debug[D_ROUTE]) {
1996-10-13 06:03:00 +04:00
printf("iso_netof: class A net len is now %d\n", len);
}
#endif
} else if (IN_CLASSB(o986->o986_inetaddr)) {
len += 4 - IN_CLASSB_NSHIFT / 8;
#ifdef ARGO_DEBUG
if (argo_debug[D_ROUTE]) {
1996-10-13 06:03:00 +04:00
printf("iso_netof: class B net len is now %d\n", len);
}
#endif
} else {
len += 4 - IN_CLASSC_NSHIFT / 8;
#ifdef ARGO_DEBUG
if (argo_debug[D_ROUTE]) {
1996-10-13 06:03:00 +04:00
printf("iso_netof: class C net len is now %d\n", len);
}
#endif
}
} else
len = 0;
} break;
default:
len = 0;
}
memcpy(buf, (void *) isoa, len);
#ifdef ARGO_DEBUG
if (argo_debug[D_ROUTE]) {
1996-10-13 06:03:00 +04:00
printf("iso_netof: isoa ");
dump_buf(isoa, len);
1996-10-13 06:03:00 +04:00
printf("iso_netof: net ");
dump_buf(buf, len);
}
#endif
return len;
}
#endif /* notdef */
/*
* Generic iso control operations (ioctl's).
* Ifp is 0 if not an interface-specific ioctl.
*/
/* ARGSUSED */
int
iso_control(struct socket *so, u_long cmd, void *data, struct ifnet *ifp,
2005-12-11 15:16:03 +03:00
struct lwp *l)
{
2000-03-30 16:51:13 +04:00
struct iso_ifreq *ifr = (struct iso_ifreq *) data;
struct iso_ifaddr *ia = 0;
struct iso_aliasreq *ifra = (struct iso_aliasreq *) data;
int error, hostIsNew, maskIsNew;
/*
* Find address for this interface, if it exists.
*/
if (ifp)
Eliminate address family-specific route caches (struct route, struct route_in6, struct route_iso), replacing all caches with a struct route. The principle benefit of this change is that all of the protocol families can benefit from route cache-invalidation, which is necessary for correct routing. Route-cache invalidation fixes an ancient PR, kern/3508, at long last; it fixes various other PRs, also. Discussions with and ideas from Joerg Sonnenberger influenced this work tremendously. Of course, all design oversights and bugs are mine. DETAILS 1 I added to each address family a pool of sockaddrs. I have introduced routines for allocating, copying, and duplicating, and freeing sockaddrs: struct sockaddr *sockaddr_alloc(sa_family_t af, int flags); struct sockaddr *sockaddr_copy(struct sockaddr *dst, const struct sockaddr *src); struct sockaddr *sockaddr_dup(const struct sockaddr *src, int flags); void sockaddr_free(struct sockaddr *sa); sockaddr_alloc() returns either a sockaddr from the pool belonging to the specified family, or NULL if the pool is exhausted. The returned sockaddr has the right size for that family; sa_family and sa_len fields are initialized to the family and sockaddr length---e.g., sa_family = AF_INET and sa_len = sizeof(struct sockaddr_in). sockaddr_free() puts the given sockaddr back into its family's pool. sockaddr_dup() and sockaddr_copy() work analogously to strdup() and strcpy(), respectively. sockaddr_copy() KASSERTs that the family of the destination and source sockaddrs are alike. The 'flags' argumet for sockaddr_alloc() and sockaddr_dup() is passed directly to pool_get(9). 2 I added routines for initializing sockaddrs in each address family, sockaddr_in_init(), sockaddr_in6_init(), sockaddr_iso_init(), etc. They are fairly self-explanatory. 3 structs route_in6 and route_iso are no more. All protocol families use struct route. I have changed the route cache, 'struct route', so that it does not contain storage space for a sockaddr. Instead, struct route points to a sockaddr coming from the pool the sockaddr belongs to. I added a new method to struct route, rtcache_setdst(), for setting the cache destination: int rtcache_setdst(struct route *, const struct sockaddr *); rtcache_setdst() returns 0 on success, or ENOMEM if no memory is available to create the sockaddr storage. It is now possible for rtcache_getdst() to return NULL if, say, rtcache_setdst() failed. I check the return value for NULL everywhere in the kernel. 4 Each routing domain (struct domain) has a list of live route caches, dom_rtcache. rtflushall(sa_family_t af) looks up the domain indicated by 'af', walks the domain's list of route caches and invalidates each one.
2007-05-03 00:40:22 +04:00
TAILQ_FOREACH(ia, &iso_ifaddr, ia_list)
if (ia->ia_ifp == ifp)
break;
switch (cmd) {
case SIOCAIFADDR_ISO:
case SIOCDIFADDR_ISO:
if (ifra->ifra_addr.siso_family == AF_ISO)
for (; ia != 0; ia = ia->ia_list.tqe_next) {
if (ia->ia_ifp == ifp &&
SAME_ISOADDR(&ia->ia_addr, &ifra->ifra_addr))
break;
}
if (cmd == SIOCDIFADDR_ISO && ia == 0)
return (EADDRNOTAVAIL);
/* FALLTHROUGH */
#if 0
case SIOCSIFADDR:
case SIOCSIFNETMASK:
case SIOCSIFDSTADDR:
#endif
2006-10-26 03:40:57 +04:00
if (l == 0 || kauth_authorize_network(l->l_cred,
KAUTH_NETWORK_INTERFACE,
KAUTH_REQ_NETWORK_INTERFACE_SETPRIV, ifp, (void *)cmd,
NULL))
return (EPERM);
if (ifp == 0)
panic("iso_control");
if (ia == 0) {
2008-12-17 23:51:31 +03:00
ia = malloc(sizeof(*ia),
2004-04-18 22:54:03 +04:00
M_IFADDR, M_WAITOK|M_ZERO);
if (ia == 0)
return (ENOBUFS);
TAILQ_INSERT_TAIL(&iso_ifaddr, ia, ia_list);
IFAREF(&ia->ia_ifa);
2007-12-06 03:28:36 +03:00
ifa_insert(ifp, &ia->ia_ifa);
ia->ia_ifa.ifa_addr = sisotosa(&ia->ia_addr);
ia->ia_ifa.ifa_dstaddr = sisotosa(&ia->ia_dstaddr);
ia->ia_ifa.ifa_netmask = sisotosa(&ia->ia_sockmask);
ia->ia_ifp = ifp;
if ((ifp->if_flags & IFF_LOOPBACK) == 0)
iso_interfaces++;
}
break;
case SIOCGIFADDR_ISO:
case SIOCGIFNETMASK_ISO:
case SIOCGIFDSTADDR_ISO:
if (ia == 0)
return (EADDRNOTAVAIL);
break;
}
switch (cmd) {
case SIOCGIFADDR_ISO:
ifr->ifr_Addr = ia->ia_addr;
break;
case SIOCGIFDSTADDR_ISO:
if ((ifp->if_flags & IFF_POINTOPOINT) == 0)
return (EINVAL);
ifr->ifr_Addr = ia->ia_dstaddr;
break;
case SIOCGIFNETMASK_ISO:
ifr->ifr_Addr = ia->ia_sockmask;
break;
case SIOCAIFADDR_ISO:
maskIsNew = 0;
hostIsNew = 1;
error = 0;
if (ia->ia_addr.siso_family == AF_ISO) {
if (ifra->ifra_addr.siso_len == 0) {
ifra->ifra_addr = ia->ia_addr;
hostIsNew = 0;
} else if (SAME_ISOADDR(&ia->ia_addr, &ifra->ifra_addr))
hostIsNew = 0;
}
if (ifra->ifra_mask.siso_len) {
iso_ifscrub(ifp, ia);
ia->ia_sockmask = ifra->ifra_mask;
maskIsNew = 1;
}
if ((ifp->if_flags & IFF_POINTOPOINT) &&
(ifra->ifra_dstaddr.siso_family == AF_ISO)) {
iso_ifscrub(ifp, ia);
ia->ia_dstaddr = ifra->ifra_dstaddr;
maskIsNew = 1; /* We lie; but the effect's the same */
}
if (ifra->ifra_addr.siso_family == AF_ISO &&
(hostIsNew || maskIsNew))
error = iso_ifinit(ifp, ia, &ifra->ifra_addr, 0);
if (ifra->ifra_snpaoffset)
ia->ia_snpaoffset = ifra->ifra_snpaoffset;
return (error);
case SIOCDIFADDR_ISO:
iso_purgeaddr(&ia->ia_ifa);
break;
#define cmdbyte(x) (((x) >> 8) & 0xff)
default:
if (cmdbyte(cmd) == 'a')
2005-12-11 15:16:03 +03:00
return (snpac_ioctl(so, cmd, data, l));
*** 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
return ENOTTY;
}
return (0);
}
void
iso_purgeaddr(struct ifaddr *ifa)
{
struct ifnet *ifp = ifa->ifa_ifp;
struct iso_ifaddr *ia = (void *) ifa;
iso_ifscrub(ifp, ia);
2007-12-06 03:28:36 +03:00
ifa_remove(ifp, &ia->ia_ifa);
TAILQ_REMOVE(&iso_ifaddr, ia, ia_list);
IFAFREE(&ia->ia_ifa);
}
void
iso_purgeif(struct ifnet *ifp)
{
if_purgeaddrs(ifp, AF_ISO, iso_purgeaddr);
}
/*
* Delete any existing route for an interface.
*/
void
iso_ifscrub(struct ifnet *ifp, struct iso_ifaddr *ia)
{
int nsellength = ia->ia_addr.siso_tlen;
if ((ia->ia_flags & IFA_ROUTE) == 0)
return;
ia->ia_addr.siso_tlen = 0;
if (ifp->if_flags & IFF_LOOPBACK)
rtinit(&(ia->ia_ifa), (int) RTM_DELETE, RTF_HOST);
else if (ifp->if_flags & IFF_POINTOPOINT)
rtinit(&(ia->ia_ifa), (int) RTM_DELETE, RTF_HOST);
else {
rtinit(&(ia->ia_ifa), (int) RTM_DELETE, 0);
}
ia->ia_addr.siso_tlen = nsellength;
ia->ia_flags &= ~IFA_ROUTE;
}
/*
* Initialize an interface's internet address
* and routing table entry.
*/
int
iso_ifinit(struct ifnet *ifp, struct iso_ifaddr *ia, struct sockaddr_iso *siso,
int scrub)
{
struct sockaddr_iso oldaddr;
int s = splnet(), error, nsellength;
oldaddr = ia->ia_addr;
ia->ia_addr = *siso;
/*
* Give the interface a chance to initialize
* if this is its first address,
* and to validate the address if necessary.
*/
*** 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 ((error = (*ifp->if_ioctl)(ifp, SIOCINITIFADDR, ia)) != 0) {
splx(s);
ia->ia_addr = oldaddr;
return (error);
}
if (scrub) {
ia->ia_ifa.ifa_addr = sisotosa(&oldaddr);
iso_ifscrub(ifp, ia);
ia->ia_ifa.ifa_addr = sisotosa(&ia->ia_addr);
}
/*
* XXX -- The following is here temporarily out of laziness in not
* changing every ethernet driver's if_ioctl routine
*** 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
*
* XXX extract llc_ifinit() and call from ether_ioctl(),
* XXX fddi_ioctl(). --dyoung
*
*/
if (ifp->if_type == IFT_ETHER || ifp->if_type == IFT_FDDI) {
ia->ia_ifa.ifa_rtrequest = llc_rtrequest;
ia->ia_ifa.ifa_flags |= RTF_CLONING;
}
/*
* Add route for the network.
*/
nsellength = ia->ia_addr.siso_tlen;
ia->ia_addr.siso_tlen = 0;
if (ifp->if_flags & IFF_LOOPBACK) {
ia->ia_ifa.ifa_dstaddr = ia->ia_ifa.ifa_addr;
error = rtinit(&(ia->ia_ifa), (int) RTM_ADD, RTF_HOST | RTF_UP);
} else if (ifp->if_flags & IFF_POINTOPOINT &&
ia->ia_dstaddr.siso_family == AF_ISO)
error = rtinit(&(ia->ia_ifa), (int) RTM_ADD, RTF_HOST | RTF_UP);
else {
rt_maskedcopy(ia->ia_ifa.ifa_addr, ia->ia_ifa.ifa_dstaddr,
ia->ia_ifa.ifa_netmask);
ia->ia_dstaddr.siso_nlen =
min(ia->ia_addr.siso_nlen, (ia->ia_sockmask.siso_len - 6));
error = rtinit(&(ia->ia_ifa), (int) RTM_ADD, RTF_UP);
}
ia->ia_addr.siso_tlen = nsellength;
ia->ia_flags |= IFA_ROUTE;
splx(s);
return (error);
}
#ifdef notdef
struct ifaddr *
iso_ifwithidi(struct sockaddr *addr)
{
2000-03-30 16:51:13 +04:00
struct ifnet *ifp;
struct ifaddr *ifa;
u_int af = addr->sa_family;
if (af != AF_ISO)
return (0);
#ifdef ARGO_DEBUG
if (argo_debug[D_ROUTE]) {
1996-10-13 06:03:00 +04:00
printf(">>> iso_ifwithidi addr\n");
dump_isoaddr(satosiso(addr));
1996-10-13 06:03:00 +04:00
printf("\n");
}
#endif
Eliminate address family-specific route caches (struct route, struct route_in6, struct route_iso), replacing all caches with a struct route. The principle benefit of this change is that all of the protocol families can benefit from route cache-invalidation, which is necessary for correct routing. Route-cache invalidation fixes an ancient PR, kern/3508, at long last; it fixes various other PRs, also. Discussions with and ideas from Joerg Sonnenberger influenced this work tremendously. Of course, all design oversights and bugs are mine. DETAILS 1 I added to each address family a pool of sockaddrs. I have introduced routines for allocating, copying, and duplicating, and freeing sockaddrs: struct sockaddr *sockaddr_alloc(sa_family_t af, int flags); struct sockaddr *sockaddr_copy(struct sockaddr *dst, const struct sockaddr *src); struct sockaddr *sockaddr_dup(const struct sockaddr *src, int flags); void sockaddr_free(struct sockaddr *sa); sockaddr_alloc() returns either a sockaddr from the pool belonging to the specified family, or NULL if the pool is exhausted. The returned sockaddr has the right size for that family; sa_family and sa_len fields are initialized to the family and sockaddr length---e.g., sa_family = AF_INET and sa_len = sizeof(struct sockaddr_in). sockaddr_free() puts the given sockaddr back into its family's pool. sockaddr_dup() and sockaddr_copy() work analogously to strdup() and strcpy(), respectively. sockaddr_copy() KASSERTs that the family of the destination and source sockaddrs are alike. The 'flags' argumet for sockaddr_alloc() and sockaddr_dup() is passed directly to pool_get(9). 2 I added routines for initializing sockaddrs in each address family, sockaddr_in_init(), sockaddr_in6_init(), sockaddr_iso_init(), etc. They are fairly self-explanatory. 3 structs route_in6 and route_iso are no more. All protocol families use struct route. I have changed the route cache, 'struct route', so that it does not contain storage space for a sockaddr. Instead, struct route points to a sockaddr coming from the pool the sockaddr belongs to. I added a new method to struct route, rtcache_setdst(), for setting the cache destination: int rtcache_setdst(struct route *, const struct sockaddr *); rtcache_setdst() returns 0 on success, or ENOMEM if no memory is available to create the sockaddr storage. It is now possible for rtcache_getdst() to return NULL if, say, rtcache_setdst() failed. I check the return value for NULL everywhere in the kernel. 4 Each routing domain (struct domain) has a list of live route caches, dom_rtcache. rtflushall(sa_family_t af) looks up the domain indicated by 'af', walks the domain's list of route caches and invalidates each one.
2007-05-03 00:40:22 +04:00
TAILQ_FOREACH(ifp, &ifnet, if_list) {
#ifdef ARGO_DEBUG
if (argo_debug[D_ROUTE]) {
1996-10-13 06:03:00 +04:00
printf("iso_ifwithidi ifnet %s\n", ifp->if_name);
}
#endif
2007-12-04 13:31:14 +03:00
IFADDR_FOREACH(ifa, ifp) {
#ifdef ARGO_DEBUG
if (argo_debug[D_ROUTE]) {
1996-10-13 06:03:00 +04:00
printf("iso_ifwithidi address ");
dump_isoaddr(satosiso(ifa->ifa_addr));
}
#endif
if (ifa->ifa_addr->sa_family != addr->sa_family)
continue;
#ifdef ARGO_DEBUG
if (argo_debug[D_ROUTE]) {
1996-10-13 06:03:00 +04:00
printf(" af same, args to iso_eqtype:\n");
printf("0x%x ", satosiso(ifa->ifa_addr)->siso_addr);
printf(" 0x%x\n",
&satosiso(addr)->siso_addr);
}
#endif
if (iso_eqtype(&satosiso(ifa->ifa_addr)->siso_addr,
&satosiso(addr)->siso_addr)) {
#ifdef ARGO_DEBUG
if (argo_debug[D_ROUTE]) {
1996-10-13 06:03:00 +04:00
printf("ifa_ifwithidi: ifa found\n");
}
#endif
return (ifa);
}
#ifdef ARGO_DEBUG
if (argo_debug[D_ROUTE]) {
1996-10-13 06:03:00 +04:00
printf(" iso_eqtype failed\n");
}
#endif
}
}
return ((struct ifaddr *) 0);
}
#endif /* notdef */
/*
* FUNCTION: iso_ck_addr
*
* PURPOSE: return true if the iso_addr passed is
* within the legal size limit for an iso address.
*
* RETURNS: true or false
*
* SIDE EFFECTS:
*
*/
int
iso_ck_addr(struct iso_addr *isoa)
{
return (isoa->isoa_len <= 20);
}
#ifdef notdef
/*
* FUNCTION: iso_eqtype
*
* PURPOSE: Determine if two iso addresses are of the same type.
* This is flaky. Really we should consider all type
* 47 addrs to be the same - but there do exist different
* structures for 47 addrs. Gosip adds a 3rd.
*
* RETURNS: true if the addresses are the same type
*
* SIDE EFFECTS:
*
* NOTES: By type, I mean rfc986, t37, or osinet
*
* This will first compare afis. If they match, then
* if the addr is not t37, the idis must be compared.
*/
int
iso_eqtype(
struct iso_addr *isoaa, /* first addr to check */
struct iso_addr *isoab) /* other addr to check */
{
if (isoaa->isoa_afi == isoab->isoa_afi) {
if (isoaa->isoa_afi == AFI_37)
return (1);
else
2009-03-18 18:14:29 +03:00
return (!memcmp(&isoaa->isoa_u, &isoab->isoa_u, 2));
}
return (0);
}
#endif /* notdef */
/*
* FUNCTION: iso_localifa()
*
* PURPOSE: Find an interface addresss having a given destination
* or at least matching the net.
*
* RETURNS: ptr to an interface address
*
* SIDE EFFECTS:
*
* NOTES:
*/
struct iso_ifaddr *
Eliminate address family-specific route caches (struct route, struct route_in6, struct route_iso), replacing all caches with a struct route. The principle benefit of this change is that all of the protocol families can benefit from route cache-invalidation, which is necessary for correct routing. Route-cache invalidation fixes an ancient PR, kern/3508, at long last; it fixes various other PRs, also. Discussions with and ideas from Joerg Sonnenberger influenced this work tremendously. Of course, all design oversights and bugs are mine. DETAILS 1 I added to each address family a pool of sockaddrs. I have introduced routines for allocating, copying, and duplicating, and freeing sockaddrs: struct sockaddr *sockaddr_alloc(sa_family_t af, int flags); struct sockaddr *sockaddr_copy(struct sockaddr *dst, const struct sockaddr *src); struct sockaddr *sockaddr_dup(const struct sockaddr *src, int flags); void sockaddr_free(struct sockaddr *sa); sockaddr_alloc() returns either a sockaddr from the pool belonging to the specified family, or NULL if the pool is exhausted. The returned sockaddr has the right size for that family; sa_family and sa_len fields are initialized to the family and sockaddr length---e.g., sa_family = AF_INET and sa_len = sizeof(struct sockaddr_in). sockaddr_free() puts the given sockaddr back into its family's pool. sockaddr_dup() and sockaddr_copy() work analogously to strdup() and strcpy(), respectively. sockaddr_copy() KASSERTs that the family of the destination and source sockaddrs are alike. The 'flags' argumet for sockaddr_alloc() and sockaddr_dup() is passed directly to pool_get(9). 2 I added routines for initializing sockaddrs in each address family, sockaddr_in_init(), sockaddr_in6_init(), sockaddr_iso_init(), etc. They are fairly self-explanatory. 3 structs route_in6 and route_iso are no more. All protocol families use struct route. I have changed the route cache, 'struct route', so that it does not contain storage space for a sockaddr. Instead, struct route points to a sockaddr coming from the pool the sockaddr belongs to. I added a new method to struct route, rtcache_setdst(), for setting the cache destination: int rtcache_setdst(struct route *, const struct sockaddr *); rtcache_setdst() returns 0 on success, or ENOMEM if no memory is available to create the sockaddr storage. It is now possible for rtcache_getdst() to return NULL if, say, rtcache_setdst() failed. I check the return value for NULL everywhere in the kernel. 4 Each routing domain (struct domain) has a list of live route caches, dom_rtcache. rtflushall(sa_family_t af) looks up the domain indicated by 'af', walks the domain's list of route caches and invalidates each one.
2007-05-03 00:40:22 +04:00
iso_localifa(const struct sockaddr_iso *siso)
{
2000-03-30 16:51:13 +04:00
struct iso_ifaddr *ia;
Eliminate address family-specific route caches (struct route, struct route_in6, struct route_iso), replacing all caches with a struct route. The principle benefit of this change is that all of the protocol families can benefit from route cache-invalidation, which is necessary for correct routing. Route-cache invalidation fixes an ancient PR, kern/3508, at long last; it fixes various other PRs, also. Discussions with and ideas from Joerg Sonnenberger influenced this work tremendously. Of course, all design oversights and bugs are mine. DETAILS 1 I added to each address family a pool of sockaddrs. I have introduced routines for allocating, copying, and duplicating, and freeing sockaddrs: struct sockaddr *sockaddr_alloc(sa_family_t af, int flags); struct sockaddr *sockaddr_copy(struct sockaddr *dst, const struct sockaddr *src); struct sockaddr *sockaddr_dup(const struct sockaddr *src, int flags); void sockaddr_free(struct sockaddr *sa); sockaddr_alloc() returns either a sockaddr from the pool belonging to the specified family, or NULL if the pool is exhausted. The returned sockaddr has the right size for that family; sa_family and sa_len fields are initialized to the family and sockaddr length---e.g., sa_family = AF_INET and sa_len = sizeof(struct sockaddr_in). sockaddr_free() puts the given sockaddr back into its family's pool. sockaddr_dup() and sockaddr_copy() work analogously to strdup() and strcpy(), respectively. sockaddr_copy() KASSERTs that the family of the destination and source sockaddrs are alike. The 'flags' argumet for sockaddr_alloc() and sockaddr_dup() is passed directly to pool_get(9). 2 I added routines for initializing sockaddrs in each address family, sockaddr_in_init(), sockaddr_in6_init(), sockaddr_iso_init(), etc. They are fairly self-explanatory. 3 structs route_in6 and route_iso are no more. All protocol families use struct route. I have changed the route cache, 'struct route', so that it does not contain storage space for a sockaddr. Instead, struct route points to a sockaddr coming from the pool the sockaddr belongs to. I added a new method to struct route, rtcache_setdst(), for setting the cache destination: int rtcache_setdst(struct route *, const struct sockaddr *); rtcache_setdst() returns 0 on success, or ENOMEM if no memory is available to create the sockaddr storage. It is now possible for rtcache_getdst() to return NULL if, say, rtcache_setdst() failed. I check the return value for NULL everywhere in the kernel. 4 Each routing domain (struct domain) has a list of live route caches, dom_rtcache. rtflushall(sa_family_t af) looks up the domain indicated by 'af', walks the domain's list of route caches and invalidates each one.
2007-05-03 00:40:22 +04:00
const char *cp1, *cp2, *cp3;
2000-03-30 16:51:13 +04:00
struct ifnet *ifp;
struct iso_ifaddr *ia_maybe = 0;
/*
* We make one pass looking for both net matches and an exact
* dst addr.
*/
Eliminate address family-specific route caches (struct route, struct route_in6, struct route_iso), replacing all caches with a struct route. The principle benefit of this change is that all of the protocol families can benefit from route cache-invalidation, which is necessary for correct routing. Route-cache invalidation fixes an ancient PR, kern/3508, at long last; it fixes various other PRs, also. Discussions with and ideas from Joerg Sonnenberger influenced this work tremendously. Of course, all design oversights and bugs are mine. DETAILS 1 I added to each address family a pool of sockaddrs. I have introduced routines for allocating, copying, and duplicating, and freeing sockaddrs: struct sockaddr *sockaddr_alloc(sa_family_t af, int flags); struct sockaddr *sockaddr_copy(struct sockaddr *dst, const struct sockaddr *src); struct sockaddr *sockaddr_dup(const struct sockaddr *src, int flags); void sockaddr_free(struct sockaddr *sa); sockaddr_alloc() returns either a sockaddr from the pool belonging to the specified family, or NULL if the pool is exhausted. The returned sockaddr has the right size for that family; sa_family and sa_len fields are initialized to the family and sockaddr length---e.g., sa_family = AF_INET and sa_len = sizeof(struct sockaddr_in). sockaddr_free() puts the given sockaddr back into its family's pool. sockaddr_dup() and sockaddr_copy() work analogously to strdup() and strcpy(), respectively. sockaddr_copy() KASSERTs that the family of the destination and source sockaddrs are alike. The 'flags' argumet for sockaddr_alloc() and sockaddr_dup() is passed directly to pool_get(9). 2 I added routines for initializing sockaddrs in each address family, sockaddr_in_init(), sockaddr_in6_init(), sockaddr_iso_init(), etc. They are fairly self-explanatory. 3 structs route_in6 and route_iso are no more. All protocol families use struct route. I have changed the route cache, 'struct route', so that it does not contain storage space for a sockaddr. Instead, struct route points to a sockaddr coming from the pool the sockaddr belongs to. I added a new method to struct route, rtcache_setdst(), for setting the cache destination: int rtcache_setdst(struct route *, const struct sockaddr *); rtcache_setdst() returns 0 on success, or ENOMEM if no memory is available to create the sockaddr storage. It is now possible for rtcache_getdst() to return NULL if, say, rtcache_setdst() failed. I check the return value for NULL everywhere in the kernel. 4 Each routing domain (struct domain) has a list of live route caches, dom_rtcache. rtflushall(sa_family_t af) looks up the domain indicated by 'af', walks the domain's list of route caches and invalidates each one.
2007-05-03 00:40:22 +04:00
TAILQ_FOREACH(ia, &iso_ifaddr, ia_list) {
if ((ifp = ia->ia_ifp) == 0 || ((ifp->if_flags & IFF_UP) == 0))
continue;
if (ifp->if_flags & IFF_POINTOPOINT) {
if ((ia->ia_dstaddr.siso_family == AF_ISO) &&
SAME_ISOADDR(&ia->ia_dstaddr, siso))
return (ia);
else if (SAME_ISOADDR(&ia->ia_addr, siso))
ia_maybe = ia;
continue;
}
if (ia->ia_sockmask.siso_len) {
char *cplim = ia->ia_sockmask.siso_len +
(char *) &ia->ia_sockmask;
cp1 = ia->ia_sockmask.siso_data;
cp2 = siso->siso_data;
cp3 = ia->ia_addr.siso_data;
while (cp1 < cplim)
if (*cp1++ & (*cp2++ ^ *cp3++))
goto next;
ia_maybe = ia;
}
if (SAME_ISOADDR(&ia->ia_addr, siso))
return ia;
next: ;
}
return ia_maybe;
}
/*
* FUNCTION: iso_nlctloutput
*
* PURPOSE: Set options at the network level
*
* RETURNS: E*
*
* SIDE EFFECTS:
*
* NOTES: This could embody some of the functions of
* rclnp_ctloutput and cons_ctloutput.
*/
int
iso_nlctloutput(
int cmd, /* command:set or get */
int optname, /* option of interest */
void * pcb, /* nl pcb */
struct mbuf *m) /* data for set, buffer for get */
{
int error = 0; /* return value */
void * data; /* data for option */
int data_len; /* data's length */
#ifdef ARGO_DEBUG
if (argo_debug[D_ISO]) {
1996-10-13 06:03:00 +04:00
printf("iso_nlctloutput: cmd %x, opt %x, pcb %p, m %p\n",
1996-10-11 03:12:43 +04:00
cmd, optname, pcb, m);
}
#endif
if ((cmd != PRCO_GETOPT) && (cmd != PRCO_SETOPT))
return (EOPNOTSUPP);
data = mtod(m, void *);
data_len = (m)->m_len;
#ifdef ARGO_DEBUG
if (argo_debug[D_ISO]) {
1996-10-13 06:03:00 +04:00
printf("iso_nlctloutput: data is:\n");
dump_buf(data, data_len);
}
#endif
switch (optname) {
default:
error = EOPNOTSUPP;
}
if (cmd == PRCO_SETOPT)
m_freem(m);
return error;
}
#endif /* ISO */
#ifdef ARGO_DEBUG
/*
* FUNCTION: dump_isoaddr
*
* PURPOSE: debugging
*
* RETURNS: nada
*
*/
void
dump_isoaddr(const struct sockaddr_iso *s)
{
if (s->siso_family == AF_ISO) {
1996-10-13 06:03:00 +04:00
printf("ISO address: suffixlen %d, %s\n",
s->siso_tlen, clnp_saddr_isop(s));
} else if (s->siso_family == AF_INET) {
/* hack */
const struct sockaddr_in *sin = satocsin(s);
1996-10-13 06:03:00 +04:00
printf("%d.%d.%d.%d: %d",
(sin->sin_addr.s_addr >> 24) & 0xff,
(sin->sin_addr.s_addr >> 16) & 0xff,
(sin->sin_addr.s_addr >> 8) & 0xff,
(sin->sin_addr.s_addr) & 0xff,
sin->sin_port);
}
}
#endif /* ARGO_DEBUG */
struct queue {
struct queue *q_next, *q_prev;
};
/*
* FUNCTION: iso_insque
*
* PURPOSE: insert an element into a queue
*
* RETURNS:
*/
void
iso_insque(void *v1, void *v2)
{
struct queue *elem = v1, *head = v2;
struct queue *next;
next = head->q_next;
elem->q_next = next;
head->q_next = elem;
elem->q_prev = head;
next->q_prev = elem;
}
/*
* FUNCTION: iso_remque
*
* PURPOSE: remove an element from a queue
*
* RETURNS:
*/
void
iso_remque(void *v)
{
struct queue *elem = v;
struct queue *next, *prev;
next = elem->q_next;
prev = elem->q_prev;
next->q_prev = prev;
prev->q_next = next;
elem->q_prev = NULL;
}