Wed Mar 18 05:14:04 2009 UTC ()
Pull up following revision(s) (requested by plunky in ticket #570):
	usr.sbin/btpand/tap.c: revision 1.2
use the generic SIOCALIFADDR to add an active link layer address
instead of the (soon to be) deprecated SIOCSIFPHYADDR


(snj)
diff -r1.1 -r1.1.6.1 src/usr.sbin/btpand/tap.c

cvs diff -r1.1 -r1.1.6.1 src/usr.sbin/btpand/tap.c (expand / switch to unified diff)

--- src/usr.sbin/btpand/tap.c 2008/08/17 13:20:57 1.1
+++ src/usr.sbin/btpand/tap.c 2009/03/18 05:14:04 1.1.6.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: tap.c,v 1.1 2008/08/17 13:20:57 plunky Exp $ */ 1/* $NetBSD: tap.c,v 1.1.6.1 2009/03/18 05:14:04 snj Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2008 Iain Hibbert 4 * Copyright (c) 2008 Iain Hibbert
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -16,81 +16,82 @@ @@ -16,81 +16,82 @@
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28#include <sys/cdefs.h> 28#include <sys/cdefs.h>
29__RCSID("$NetBSD: tap.c,v 1.1 2008/08/17 13:20:57 plunky Exp $"); 29__RCSID("$NetBSD: tap.c,v 1.1.6.1 2009/03/18 05:14:04 snj Exp $");
30 30
31#include <sys/ioctl.h> 31#include <sys/ioctl.h>
32#include <sys/uio.h> 32#include <sys/uio.h>
33 33
34#include <net/if_dl.h> 34#include <net/if_dl.h>
35#include <net/if_tap.h> 35#include <net/if_tap.h>
36 36
37#include <fcntl.h> 37#include <fcntl.h>
38#include <unistd.h> 38#include <unistd.h>
39#include <util.h> 39#include <util.h>
40 40
41#include "btpand.h" 41#include "btpand.h"
42 42
43static bool tap_send(channel_t *, packet_t *); 43static bool tap_send(channel_t *, packet_t *);
44static bool tap_recv(packet_t *); 44static bool tap_recv(packet_t *);
45 45
46void 46void
47tap_init(void) 47tap_init(void)
48{ 48{
49 channel_t *chan; 49 channel_t *chan;
50 struct sockaddr_dl *sdl; 50 struct sockaddr_dl *sdl;
51 struct ifaliasreq ifra; 51 struct if_laddrreq iflr;
52 struct ifreq ifr; 52 struct ifreq ifr;
53 int fd, s; 53 int fd, s;
54 54
55 fd = open(interface_name, O_RDWR); 55 fd = open(interface_name, O_RDWR);
56 if (fd == -1) { 56 if (fd == -1) {
57 log_err("Could not open \"%s\": %m", interface_name); 57 log_err("Could not open \"%s\": %m", interface_name);
58 exit(EXIT_FAILURE); 58 exit(EXIT_FAILURE);
59 } 59 }
60 60
61 memset(&ifr, 0, sizeof(ifr)); 61 memset(&ifr, 0, sizeof(ifr));
62 if (ioctl(fd, TAPGIFNAME, &ifr) == -1) { 62 if (ioctl(fd, TAPGIFNAME, &ifr) == -1) {
63 log_err("Could not get interface name: %m"); 63 log_err("Could not get interface name: %m");
64 exit(EXIT_FAILURE); 64 exit(EXIT_FAILURE);
65 } 65 }
66 66
67 s = socket(PF_LINK, SOCK_DGRAM, 0); 67 s = socket(PF_LINK, SOCK_DGRAM, 0);
68 if (s == -1) { 68 if (s == -1) {
69 log_err("Could not open PF_LINK socket: %m"); 69 log_err("Could not open PF_LINK socket: %m");
70 exit(EXIT_FAILURE); 70 exit(EXIT_FAILURE);
71 } 71 }
72 72
73 memset(&ifra, 0, sizeof(ifra)); 73 memset(&iflr, 0, sizeof(iflr));
74 memcpy(ifra.ifra_name, ifr.ifr_name, IFNAMSIZ); 74 memcpy(iflr.iflr_name, ifr.ifr_name, IFNAMSIZ);
 75 iflr.flags = IFLR_ACTIVE;
75 76
76 sdl = satosdl(&ifra.ifra_addr); 77 sdl = satosdl(sstosa(&iflr.addr));
77 sdl->sdl_family = AF_LINK; 78 sdl->sdl_family = AF_LINK;
78 sdl->sdl_len = sizeof(struct sockaddr_dl); 79 sdl->sdl_len = sizeof(struct sockaddr_dl);
79 sdl->sdl_alen = ETHER_ADDR_LEN; 80 sdl->sdl_alen = ETHER_ADDR_LEN;
80 b2eaddr(LLADDR(sdl), &local_bdaddr); 81 b2eaddr(LLADDR(sdl), &local_bdaddr);
81 82
82 if (ioctl(s, SIOCSIFPHYADDR, &ifra) == -1) { 83 if (ioctl(s, SIOCALIFADDR, &iflr) == -1) {
83 log_err("Could not set %s physical address: %m", ifra.ifra_name); 84 log_err("Could not add %s link address: %m", iflr.iflr_name);
84 exit(EXIT_FAILURE); 85 exit(EXIT_FAILURE);
85 } 86 }
86 87
87 if (ioctl(s, SIOCGIFFLAGS, &ifr) == -1) { 88 if (ioctl(s, SIOCGIFFLAGS, &ifr) == -1) {
88 log_err("Could not get interface flags: %m"); 89 log_err("Could not get interface flags: %m");
89 exit(EXIT_FAILURE); 90 exit(EXIT_FAILURE);
90 } 91 }
91 92
92 if ((ifr.ifr_flags & IFF_UP) == 0) { 93 if ((ifr.ifr_flags & IFF_UP) == 0) {
93 ifr.ifr_flags |= IFF_UP; 94 ifr.ifr_flags |= IFF_UP;
94 95
95 if (ioctl(s, SIOCSIFFLAGS, &ifr) == -1) { 96 if (ioctl(s, SIOCSIFFLAGS, &ifr) == -1) {
96 log_err("Could not set IFF_UP: %m"); 97 log_err("Could not set IFF_UP: %m");