From f4a4d0ccce6152a6e48d345c33b3db9dbdaad529 Mon Sep 17 00:00:00 2001 From: mpi <> Date: Thu, 10 Sep 2015 08:55:03 +0000 Subject: Remove link_addr(3). A function to encode the name of an interface in a sockaddr_dl is a questionnable interface. But now it makes it harder to properly reference ifp becauses of this. Set sdl_index to the index of the corresponding interface when constructing a routing message. Ridding previous libc crank. ok guenther@, deraadt@, dlg@ --- src/lib/libc/net/Makefile.inc | 5 +- src/lib/libc/net/link_addr.3 | 127 ------------------------------------------ src/lib/libc/net/link_ntoa.3 | 78 ++++++++++++++++++++++++++ src/lib/libc/net/linkaddr.c | 80 +------------------------- 4 files changed, 81 insertions(+), 209 deletions(-) delete mode 100644 src/lib/libc/net/link_addr.3 create mode 100644 src/lib/libc/net/link_ntoa.3 diff --git a/src/lib/libc/net/Makefile.inc b/src/lib/libc/net/Makefile.inc index b063c4a1fa..b4d99987c5 100644 --- a/src/lib/libc/net/Makefile.inc +++ b/src/lib/libc/net/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.56 2014/08/31 02:27:37 guenther Exp $ +# $OpenBSD: Makefile.inc,v 1.57 2015/09/10 08:55:03 mpi Exp $ # net sources .PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/net ${LIBCSRCDIR}/net @@ -32,7 +32,7 @@ MAN+= byteorder.3 ethers.3 gai_strerror.3 getaddrinfo.3 gethostbyname.3 \ getifaddrs.3 getnameinfo.3 getnetent.3 getpeereid.3 getprotoent.3 \ getrrsetbyname.3 getservent.3 htonl.3 if_indextoname.3 \ inet_addr.3 inet_lnaof.3 inet_net.3 inet_ntop.3 \ - inet6_opt_init.3 inet6_rth_space.3 link_addr.3 \ + inet6_opt_init.3 inet6_rth_space.3 link_ntoa.3 \ rcmd.3 rcmdsh.3 resolver.3 sockatmark.3 MLINKS+=byteorder.3 htobe16.3 byteorder.3 htobe32.3 byteorder.3 htobe64.3 \ @@ -70,7 +70,6 @@ MLINKS+=inet_addr.3 inet_aton.3 inet_addr.3 inet_network.3 \ MLINKS+=inet_lnaof.3 inet_makeaddr.3 inet_lnaof.3 inet_netof.3 MLINKS+=inet_ntop.3 inet_pton.3 MLINKS+=inet_net.3 inet_net_ntop.3 inet_net.3 inet_net_pton.3 -MLINKS+=link_addr.3 link_ntoa.3 MLINKS+=rcmd.3 iruserok.3 rcmd.3 rresvport.3 rcmd.3 ruserok.3 \ rcmd.3 rresvport_af.3 rcmd.3 rcmd_af.3 rcmd.3 iruserok_sa.3 MLINKS+=resolver.3 dn_comp.3 resolver.3 dn_expand.3 resolver.3 res_init.3 \ diff --git a/src/lib/libc/net/link_addr.3 b/src/lib/libc/net/link_addr.3 deleted file mode 100644 index f234fe84cc..0000000000 --- a/src/lib/libc/net/link_addr.3 +++ /dev/null @@ -1,127 +0,0 @@ -.\" $OpenBSD: link_addr.3,v 1.13 2013/06/05 03:39:23 tedu Exp $ -.\" -.\" Copyright (c) 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Donn Seeley at BSDI. -.\" -.\" 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. -.\" -.Dd $Mdocdate: June 5 2013 $ -.Dt LINK_ADDR 3 -.Os -.Sh NAME -.Nm link_addr , -.Nm link_ntoa -.Nd elementary address specification routines for link level access -.Sh SYNOPSIS -.In sys/types.h -.In sys/socket.h -.In net/if_dl.h -.Ft void -.Fn link_addr "const char *addr" "struct sockaddr_dl *sdl" -.Ft char * -.Fn link_ntoa "const struct sockaddr_dl *sdl" -.Sh DESCRIPTION -The -.Fn link_addr -function interprets character strings representing -link-level addresses, returning binary information suitable -for use in system calls. -.Fn link_ntoa -takes -a link-level -address and returns an -.Tn ASCII -string representing some of the information present, -including the link level address itself, and the interface name -or number, if present. -This facility is experimental and is -still subject to change. -.Pp -For -.Fn link_addr , -the string -.Fa addr -may contain -an optional network interface identifier of the form -.Dq name unit-number , -suitable for the first argument to -.Xr ifconfig 8 , -followed in all cases by a colon and -an interface address in the form of -groups of hexadecimal digits -separated by periods. -Each group represents a byte of address; -address bytes are filled left to right from -low order bytes through high order bytes. -.Pp -.\" A regular expression may make this format clearer: -.\" .Bd -literal -offset indent -.\" ([a-z]+[0-9]+:)?[0-9a-f]+(\e.[0-9a-f]+)* -.\" .Ed -.\" .Pp -Thus -.Li le0:8.0.9.13.d.30 -represents an Ethernet address -to be transmitted on the first Lance Ethernet interface. -.Sh RETURN VALUES -.Fn link_ntoa -always returns a NUL-terminated string. -.Fn link_addr -has no return value. -(See -.Sx BUGS . ) -.Sh SEE ALSO -.Xr ifconfig 8 -.Sh HISTORY -The -.Fn link_addr -and -.Fn link_ntoa -functions appeared in -.Bx 4.3 Reno . -.Sh BUGS -The returned values for -.Fn link_ntoa -reside in a static memory area. -.Pp -The function -.Fn link_addr -should diagnose improperly formed input, and there should be an unambiguous -way to recognize this. -.Pp -If the -.Fa sdl_len -field of the link socket address -.Fa sdl -is 0, -.Fn link_ntoa -will not insert a colon before the interface address bytes. -If this translated address is given to -.Fn link_addr -without inserting an initial colon, -the latter will not interpret it correctly. diff --git a/src/lib/libc/net/link_ntoa.3 b/src/lib/libc/net/link_ntoa.3 new file mode 100644 index 0000000000..67a412dbc8 --- /dev/null +++ b/src/lib/libc/net/link_ntoa.3 @@ -0,0 +1,78 @@ +.\" $OpenBSD: link_ntoa.3,v 1.1 2015/09/10 08:55:03 mpi Exp $ +.\" +.\" Copyright (c) 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" Donn Seeley at BSDI. +.\" +.\" 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. +.\" +.Dd $Mdocdate: September 10 2015 $ +.Dt LINK_NTOA 3 +.Os +.Sh NAME +.Nm link_ntoa +.Nd elementary address specification routines for link level access +.Sh SYNOPSIS +.In sys/types.h +.In sys/socket.h +.In net/if_dl.h +.Ft char * +.Fn link_ntoa "const struct sockaddr_dl *sdl" +.Sh DESCRIPTION +The +.Fn link_ntoa +function takes +a link-level +address and returns an +.Tn ASCII +string representing some of the information present, +including the link level address itself, and the interface name +or number, if present. +This facility is experimental and is +still subject to change. +.Sh RETURN VALUES +.Fn link_ntoa +always returns a NUL-terminated string. +.Sh SEE ALSO +.Xr ifconfig 8 +.Sh HISTORY +The +.Fn link_ntoa +function appeared in +.Bx 4.3 Reno . +.Sh BUGS +The returned values for +.Fn link_ntoa +reside in a static memory area. +.Pp +If the +.Fa sdl_len +field of the link socket address +.Fa sdl +is 0, +.Fn link_ntoa +will not insert a colon before the interface address bytes. diff --git a/src/lib/libc/net/linkaddr.c b/src/lib/libc/net/linkaddr.c index ac96f3acdf..8f90aca8f5 100644 --- a/src/lib/libc/net/linkaddr.c +++ b/src/lib/libc/net/linkaddr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: linkaddr.c,v 1.5 2005/08/06 20:30:03 espie Exp $ */ +/* $OpenBSD: linkaddr.c,v 1.6 2015/09/10 08:55:03 mpi Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -33,84 +33,6 @@ #include #include -/* States*/ -#define NAMING 0 -#define GOTONE 1 -#define GOTTWO 2 -#define RESET 3 -/* Inputs */ -#define DIGIT (4*0) -#define END (4*1) -#define DELIM (4*2) -#define LETTER (4*3) - -void -link_addr(const char *addr, struct sockaddr_dl *sdl) -{ - char *cp = sdl->sdl_data; - char *cplim = sdl->sdl_len + (char *)sdl; - int byte = 0, state = NAMING, new; - - bzero((char *)&sdl->sdl_family, sdl->sdl_len - 1); - sdl->sdl_family = AF_LINK; - do { - state &= ~LETTER; - if ((*addr >= '0') && (*addr <= '9')) { - new = *addr - '0'; - } else if ((*addr >= 'a') && (*addr <= 'f')) { - new = *addr - 'a' + 10; - } else if ((*addr >= 'A') && (*addr <= 'F')) { - new = *addr - 'A' + 10; - } else if (*addr == 0) { - state |= END; - } else if (state == NAMING && - (((*addr >= 'A') && (*addr <= 'Z')) || - ((*addr >= 'a') && (*addr <= 'z')))) - state |= LETTER; - else - state |= DELIM; - addr++; - switch (state /* | INPUT */) { - case NAMING | DIGIT: - case NAMING | LETTER: - *cp++ = addr[-1]; - continue; - case NAMING | DELIM: - state = RESET; - sdl->sdl_nlen = cp - sdl->sdl_data; - continue; - case GOTTWO | DIGIT: - *cp++ = byte; - /* FALLTHROUGH */ - case RESET | DIGIT: - state = GOTONE; - byte = new; - continue; - case GOTONE | DIGIT: - state = GOTTWO; - byte = new + (byte << 4); - continue; - default: /* | DELIM */ - state = RESET; - *cp++ = byte; - byte = 0; - continue; - case GOTONE | END: - case GOTTWO | END: - *cp++ = byte; - /* FALLTHROUGH */ - case RESET | END: - break; - } - break; - } while (cp < cplim); - sdl->sdl_alen = cp - LLADDR(sdl); - new = cp - (char *)sdl; - if (new > sizeof(*sdl)) - sdl->sdl_len = new; - return; -} - static char hexlist[] = "0123456789abcdef"; char * -- cgit v1.2.3-55-g6feb