Sat May 2 20:07:52 2009 UTC ()
use assert() instead of _DIAGASSERT()

suggested by emax@freebsd


(plunky)
diff -r1.3 -r1.4 src/usr.sbin/btpand/bnep.c
diff -r1.1 -r1.2 src/usr.sbin/btpand/channel.c
diff -r1.1 -r1.2 src/usr.sbin/btpand/packet.c
diff -r1.2 -r1.3 src/usr.sbin/btpand/tap.c

cvs diff -r1.3 -r1.4 src/usr.sbin/btpand/bnep.c (expand / switch to unified diff)

--- src/usr.sbin/btpand/bnep.c 2009/02/04 19:24:18 1.3
+++ src/usr.sbin/btpand/bnep.c 2009/05/02 20:07:51 1.4
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: bnep.c,v 1.3 2009/02/04 19:24:18 plunky Exp $ */ 1/* $NetBSD: bnep.c,v 1.4 2009/05/02 20:07:51 plunky 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,27 +16,27 @@ @@ -16,27 +16,27 @@
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: bnep.c,v 1.3 2009/02/04 19:24:18 plunky Exp $"); 29__RCSID("$NetBSD: bnep.c,v 1.4 2009/05/02 20:07:51 plunky Exp $");
30 30
31#include <bluetooth.h> 31#include <bluetooth.h>
32#include <sdp.h> 32#include <sdp.h>
33#include <stdarg.h> 33#include <stdarg.h>
34#include <string.h> 34#include <string.h>
35 35
36#include "btpand.h" 36#include "btpand.h"
37#include "bnep.h" 37#include "bnep.h"
38 38
39static bool bnep_recv_extension(packet_t *); 39static bool bnep_recv_extension(packet_t *);
40static size_t bnep_recv_control(channel_t *, uint8_t *, size_t, bool); 40static size_t bnep_recv_control(channel_t *, uint8_t *, size_t, bool);
41static size_t bnep_recv_control_command_not_understood(channel_t *, uint8_t *, size_t); 41static size_t bnep_recv_control_command_not_understood(channel_t *, uint8_t *, size_t);
42static size_t bnep_recv_setup_connection_req(channel_t *, uint8_t *, size_t); 42static size_t bnep_recv_setup_connection_req(channel_t *, uint8_t *, size_t);
@@ -565,27 +565,27 @@ bnep_recv_filter_multi_addr_rsp(channel_ @@ -565,27 +565,27 @@ bnep_recv_filter_multi_addr_rsp(channel_
565 ether_ntoa((struct ether_addr *)chan->raddr), rsp); 565 ether_ntoa((struct ether_addr *)chan->raddr), rsp);
566 566
567 /* we did not send any filter_multi_addr_set message */ 567 /* we did not send any filter_multi_addr_set message */
568 return 2; 568 return 2;
569} 569}
570 570
571void 571void
572bnep_send_control(channel_t *chan, uint8_t type, ...) 572bnep_send_control(channel_t *chan, uint8_t type, ...)
573{ 573{
574 packet_t *pkt; 574 packet_t *pkt;
575 uint8_t *p; 575 uint8_t *p;
576 va_list ap; 576 va_list ap;
577 577
578 _DIAGASSERT(chan->state != CHANNEL_CLOSED); 578 assert(chan->state != CHANNEL_CLOSED);
579 579
580 pkt = packet_alloc(chan); 580 pkt = packet_alloc(chan);
581 if (pkt == NULL) 581 if (pkt == NULL)
582 return; 582 return;
583 583
584 p = pkt->ptr; 584 p = pkt->ptr;
585 va_start(ap, type); 585 va_start(ap, type);
586 586
587 *p++ = BNEP_CONTROL; 587 *p++ = BNEP_CONTROL;
588 *p++ = type; 588 *p++ = type;
589 589
590 switch(type) { 590 switch(type) {
591 case BNEP_CONTROL_COMMAND_NOT_UNDERSTOOD: 591 case BNEP_CONTROL_COMMAND_NOT_UNDERSTOOD:

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

--- src/usr.sbin/btpand/channel.c 2008/08/17 13:20:57 1.1
+++ src/usr.sbin/btpand/channel.c 2009/05/02 20:07:51 1.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: channel.c,v 1.1 2008/08/17 13:20:57 plunky Exp $ */ 1/* $NetBSD: channel.c,v 1.2 2009/05/02 20:07:51 plunky 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,27 +16,27 @@ @@ -16,27 +16,27 @@
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: channel.c,v 1.1 2008/08/17 13:20:57 plunky Exp $"); 29__RCSID("$NetBSD: channel.c,v 1.2 2009/05/02 20:07:51 plunky Exp $");
30 30
31#include <sys/ioctl.h> 31#include <sys/ioctl.h>
32 32
33#include <unistd.h> 33#include <unistd.h>
34 34
35#include "btpand.h" 35#include "btpand.h"
36 36
37static struct chlist channel_list; 37static struct chlist channel_list;
38static int channel_count; 38static int channel_count;
39static int channel_tick; 39static int channel_tick;
40 40
41static void channel_start(int, short, void *); 41static void channel_start(int, short, void *);
42static void channel_read(int, short, void *); 42static void channel_read(int, short, void *);
@@ -66,28 +66,28 @@ channel_alloc(void) @@ -66,28 +66,28 @@ channel_alloc(void)
66 chan->state = CHANNEL_CLOSED; 66 chan->state = CHANNEL_CLOSED;
67 LIST_INSERT_HEAD(&channel_list, chan, next); 67 LIST_INSERT_HEAD(&channel_list, chan, next);
68 68
69 server_update(++channel_count); 69 server_update(++channel_count);
70 70
71 return chan; 71 return chan;
72} 72}
73 73
74bool 74bool
75channel_open(channel_t *chan, int fd) 75channel_open(channel_t *chan, int fd)
76{ 76{
77 int n; 77 int n;
78 78
79 _DIAGASSERT(chan->refcnt == 0); 79 assert(chan->refcnt == 0);
80 _DIAGASSERT(chan->state != CHANNEL_CLOSED); 80 assert(chan->state != CHANNEL_CLOSED);
81 81
82 if (chan->mtu > 0) { 82 if (chan->mtu > 0) {
83 chan->sendbuf = malloc(chan->mtu); 83 chan->sendbuf = malloc(chan->mtu);
84 if (chan->sendbuf == NULL) { 84 if (chan->sendbuf == NULL) {
85 log_err("Could not malloc channel sendbuf: %m"); 85 log_err("Could not malloc channel sendbuf: %m");
86 return false; 86 return false;
87 } 87 }
88 } 88 }
89 89
90 n = 1; 90 n = 1;
91 if (ioctl(fd, FIONBIO, &n) == -1) { 91 if (ioctl(fd, FIONBIO, &n) == -1) {
92 log_err("Could not set non-blocking IO: %m"); 92 log_err("Could not set non-blocking IO: %m");
93 return false; 93 return false;
@@ -104,55 +104,55 @@ channel_open(channel_t *chan, int fd) @@ -104,55 +104,55 @@ channel_open(channel_t *chan, int fd)
104 chan->refcnt++; 104 chan->refcnt++;
105 chan->fd = fd; 105 chan->fd = fd;
106 106
107 log_debug("(fd#%d)", chan->fd); 107 log_debug("(fd#%d)", chan->fd);
108 108
109 return true; 109 return true;
110} 110}
111 111
112void 112void
113channel_close(channel_t *chan) 113channel_close(channel_t *chan)
114{ 114{
115 pkthdr_t *ph; 115 pkthdr_t *ph;
116 116
117 _DIAGASSERT(chan->state != CHANNEL_CLOSED); 117 assert(chan->state != CHANNEL_CLOSED);
118 118
119 log_debug("(fd#%d)", chan->fd); 119 log_debug("(fd#%d)", chan->fd);
120 120
121 chan->state = CHANNEL_CLOSED; 121 chan->state = CHANNEL_CLOSED;
122 event_del(&chan->rd_ev); 122 event_del(&chan->rd_ev);
123 event_del(&chan->wr_ev); 123 event_del(&chan->wr_ev);
124 close(chan->fd); 124 close(chan->fd);
125 chan->refcnt--; 125 chan->refcnt--;
126 chan->tick = 0; 126 chan->tick = 0;
127 127
128 while ((ph = STAILQ_FIRST(&chan->pktlist)) != NULL) { 128 while ((ph = STAILQ_FIRST(&chan->pktlist)) != NULL) {
129 STAILQ_REMOVE_HEAD(&chan->pktlist, next); 129 STAILQ_REMOVE_HEAD(&chan->pktlist, next);
130 pkthdr_free(ph); 130 pkthdr_free(ph);
131 chan->qlen--; 131 chan->qlen--;
132 } 132 }
133 133
134 if (chan->refcnt == 0) 134 if (chan->refcnt == 0)
135 channel_free(chan); 135 channel_free(chan);
136} 136}
137 137
138void 138void
139channel_free(channel_t *chan) 139channel_free(channel_t *chan)
140{ 140{
141 141
142 _DIAGASSERT(chan->refcnt == 0); 142 assert(chan->refcnt == 0);
143 _DIAGASSERT(chan->state == CHANNEL_CLOSED); 143 assert(chan->state == CHANNEL_CLOSED);
144 _DIAGASSERT(chan->qlen == 0); 144 assert(chan->qlen == 0);
145 _DIAGASSERT(STAILQ_EMPTY(&chan->pktlist)); 145 assert(STAILQ_EMPTY(&chan->pktlist));
146 146
147 LIST_REMOVE(chan, next); 147 LIST_REMOVE(chan, next);
148 free(chan->pfilter); 148 free(chan->pfilter);
149 free(chan->mfilter); 149 free(chan->mfilter);
150 free(chan->sendbuf); 150 free(chan->sendbuf);
151 free(chan); 151 free(chan);
152 152
153 server_update(--channel_count); 153 server_update(--channel_count);
154 154
155 if (server_limit == 0) { 155 if (server_limit == 0) {
156 log_info("connection closed, exiting"); 156 log_info("connection closed, exiting");
157 exit(EXIT_SUCCESS); 157 exit(EXIT_SUCCESS);
158 } 158 }

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

--- src/usr.sbin/btpand/packet.c 2008/08/17 13:20:57 1.1
+++ src/usr.sbin/btpand/packet.c 2009/05/02 20:07:51 1.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: packet.c,v 1.1 2008/08/17 13:20:57 plunky Exp $ */ 1/* $NetBSD: packet.c,v 1.2 2009/05/02 20:07:51 plunky 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,27 +16,27 @@ @@ -16,27 +16,27 @@
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: packet.c,v 1.1 2008/08/17 13:20:57 plunky Exp $"); 29__RCSID("$NetBSD: packet.c,v 1.2 2009/05/02 20:07:51 plunky Exp $");
30 30
31#include "btpand.h" 31#include "btpand.h"
32 32
33packet_t * 33packet_t *
34packet_alloc(channel_t *chan) 34packet_alloc(channel_t *chan)
35{ 35{
36 packet_t *pkt; 36 packet_t *pkt;
37 37
38 pkt = malloc(sizeof(packet_t) + chan->mru); 38 pkt = malloc(sizeof(packet_t) + chan->mru);
39 if (pkt == NULL) { 39 if (pkt == NULL) {
40 log_err("%s() failed: %m", __func__); 40 log_err("%s() failed: %m", __func__);
41 return NULL; 41 return NULL;
42 } 42 }
@@ -65,28 +65,28 @@ packet_free(packet_t *pkt) @@ -65,28 +65,28 @@ packet_free(packet_t *pkt)
65 } 65 }
66 66
67 pkt->chan->refcnt--; 67 pkt->chan->refcnt--;
68 if (pkt->chan->refcnt == 0) 68 if (pkt->chan->refcnt == 0)
69 channel_free(pkt->chan); 69 channel_free(pkt->chan);
70 70
71 free(pkt); 71 free(pkt);
72} 72}
73 73
74void 74void
75packet_adj(packet_t *pkt, size_t size) 75packet_adj(packet_t *pkt, size_t size)
76{ 76{
77 77
78 _DIAGASSERT(pkt->refcnt == 0); 78 assert(pkt->refcnt == 0);
79 _DIAGASSERT(pkt->len >= size); 79 assert(pkt->len >= size);
80 80
81 pkt->ptr += size; 81 pkt->ptr += size;
82 pkt->len -= size; 82 pkt->len -= size;
83} 83}
84 84
85pkthdr_t * 85pkthdr_t *
86pkthdr_alloc(packet_t *pkt) 86pkthdr_alloc(packet_t *pkt)
87{ 87{
88 pkthdr_t *ph; 88 pkthdr_t *ph;
89 89
90 ph = malloc(sizeof(pkthdr_t)); 90 ph = malloc(sizeof(pkthdr_t));
91 if (ph == NULL) { 91 if (ph == NULL) {
92 log_err("%s() failed: %m", __func__); 92 log_err("%s() failed: %m", __func__);

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

--- src/usr.sbin/btpand/tap.c 2009/03/10 22:12:17 1.2
+++ src/usr.sbin/btpand/tap.c 2009/05/02 20:07:51 1.3
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: tap.c,v 1.2 2009/03/10 22:12:17 plunky Exp $ */ 1/* $NetBSD: tap.c,v 1.3 2009/05/02 20:07:51 plunky 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,27 +16,27 @@ @@ -16,27 +16,27 @@
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.2 2009/03/10 22:12:17 plunky Exp $"); 29__RCSID("$NetBSD: tap.c,v 1.3 2009/05/02 20:07:51 plunky 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
@@ -128,27 +128,27 @@ tap_send(channel_t *chan, packet_t *pkt) @@ -128,27 +128,27 @@ tap_send(channel_t *chan, packet_t *pkt)
128 ssize_t nw; 128 ssize_t nw;
129 129
130 iov[0].iov_base = pkt->dst; 130 iov[0].iov_base = pkt->dst;
131 iov[0].iov_len = ETHER_ADDR_LEN; 131 iov[0].iov_len = ETHER_ADDR_LEN;
132 iov[1].iov_base = pkt->src; 132 iov[1].iov_base = pkt->src;
133 iov[1].iov_len = ETHER_ADDR_LEN; 133 iov[1].iov_len = ETHER_ADDR_LEN;
134 iov[2].iov_base = pkt->type; 134 iov[2].iov_base = pkt->type;
135 iov[2].iov_len = ETHER_TYPE_LEN; 135 iov[2].iov_len = ETHER_TYPE_LEN;
136 iov[3].iov_base = pkt->ptr; 136 iov[3].iov_base = pkt->ptr;
137 iov[3].iov_len = pkt->len; 137 iov[3].iov_len = pkt->len;
138 138
139 /* tap device write never fails */ 139 /* tap device write never fails */
140 nw = writev(chan->fd, iov, __arraycount(iov)); 140 nw = writev(chan->fd, iov, __arraycount(iov));
141 _DIAGASSERT(nw > 0); 141 assert(nw > 0);
142 142
143 return true; 143 return true;
144} 144}
145 145
146static bool 146static bool
147tap_recv(packet_t *pkt) 147tap_recv(packet_t *pkt)
148{ 148{
149 149
150 if (pkt->len < ETHER_HDR_LEN) 150 if (pkt->len < ETHER_HDR_LEN)
151 return false; 151 return false;
152 152
153 pkt->dst = pkt->ptr; 153 pkt->dst = pkt->ptr;
154 packet_adj(pkt, ETHER_ADDR_LEN); 154 packet_adj(pkt, ETHER_ADDR_LEN);