Sun Jan 15 20:27:34 2017 UTC ()
Initial commit of a CAN socket layer, compatible with linux SoccketCAN
(but incomplete). Based on work from Robert Swindells.
(bouyer)
diff -r1.79 -r1.79.22.1 src/sys/Makefile
diff -r1.1168 -r1.1168.2.1 src/sys/conf/files
diff -r1.44 -r1.44.4.1 src/sys/net/netisr.h
diff -r1.18 -r1.18.12.1 src/sys/net/netisr_dispatch.h
diff -r0 -r1.1.2.1 src/sys/netcan/Makefile
diff -r0 -r1.1.2.1 src/sys/netcan/can.c
diff -r0 -r1.1.2.1 src/sys/netcan/can.h
diff -r0 -r1.1.2.1 src/sys/netcan/can_pcb.c
diff -r0 -r1.1.2.1 src/sys/netcan/can_pcb.h
diff -r0 -r1.1.2.1 src/sys/netcan/can_proto.c
diff -r0 -r1.1.2.1 src/sys/netcan/can_var.h
diff -r0 -r1.1.2.1 src/sys/netcan/files.netcan
diff -r0 -r1.1.2.1 src/sys/netcan/if_canloop.c
diff -r1.5 -r1.5.4.1 src/sys/rump/include/opt/opt_rumpkernel.h
diff -r1.36 -r1.36.4.1 src/sys/rump/include/rump/rumpdefs.h
diff -r1.16 -r1.16.2.1 src/sys/rump/net/Makefile.rumpnetcomp
diff -r0 -r1.1.2.1 src/sys/rump/net/lib/libnetcan/Makefile
diff -r0 -r1.1.2.1 src/sys/rump/net/lib/libnetcan/NETCAN.ioconf
diff -r0 -r1.1.2.1 src/sys/rump/net/lib/libnetcan/netcan_component.c
diff -r1.120 -r1.120.2.1 src/sys/sys/socket.h
--- src/sys/Makefile 2013/03/01 18:25:27 1.79
+++ src/sys/Makefile 2017/01/15 20:27:33 1.79.22.1
| @@ -1,19 +1,19 @@ | | | @@ -1,19 +1,19 @@ |
1 | # $NetBSD: Makefile,v 1.79 2013/03/01 18:25:27 joerg Exp $ | | 1 | # $NetBSD: Makefile,v 1.79.22.1 2017/01/15 20:27:33 bouyer Exp $ |
2 | | | 2 | |
3 | .include <bsd.own.mk> | | 3 | .include <bsd.own.mk> |
4 | | | 4 | |
5 | SUBDIR= altq arch compat dev fs miscfs \ | | 5 | SUBDIR= altq arch compat dev fs miscfs \ |
6 | net net80211 netatalk netbt netipsec netinet netinet6 \ | | 6 | net net80211 netatalk netbt netcan netipsec netinet netinet6 \ |
7 | netisdn netkey netmpls netnatm netsmb \ | | 7 | netisdn netkey netmpls netnatm netsmb \ |
8 | nfs opencrypto sys ufs uvm | | 8 | nfs opencrypto sys ufs uvm |
9 | | | 9 | |
10 | # interrupt implementation depends on the kernel within the port | | 10 | # interrupt implementation depends on the kernel within the port |
11 | #.if (${MACHINE} != "evbppc") | | 11 | #.if (${MACHINE} != "evbppc") |
12 | .if make(obj) || make(cleandir) || ${MKKMOD} != "no" | | 12 | .if make(obj) || make(cleandir) || ${MKKMOD} != "no" |
13 | SUBDIR+=modules | | 13 | SUBDIR+=modules |
14 | .endif | | 14 | .endif |
15 | #.endif | | 15 | #.endif |
16 | | | 16 | |
17 | .if make(includes) || make(obj) || make(cleandir) | | 17 | .if make(includes) || make(obj) || make(cleandir) |
18 | SUBDIR+= rump | | 18 | SUBDIR+= rump |
19 | .endif | | 19 | .endif |
--- src/sys/conf/files 2016/12/26 23:12:33 1.1168
+++ src/sys/conf/files 2017/01/15 20:27:33 1.1168.2.1
| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | # $NetBSD: files,v 1.1168 2016/12/26 23:12:33 pgoyette Exp $ | | 1 | # $NetBSD: files,v 1.1168.2.1 2017/01/15 20:27:33 bouyer Exp $ |
2 | # @(#)files.newconf 7.5 (Berkeley) 5/10/93 | | 2 | # @(#)files.newconf 7.5 (Berkeley) 5/10/93 |
3 | | | 3 | |
4 | version 20150846 | | 4 | version 20150846 |
5 | | | 5 | |
6 | # | | 6 | # |
7 | # device classes | | 7 | # device classes |
8 | # | | 8 | # |
9 | devclass disk | | 9 | devclass disk |
10 | devclass tape | | 10 | devclass tape |
11 | devclass ifnet | | 11 | devclass ifnet |
12 | devclass tty | | 12 | devclass tty |
13 | devclass audiodev | | 13 | devclass audiodev |
14 | devclass displaydev | | 14 | devclass displaydev |
| @@ -219,26 +219,27 @@ include "dev/sysmon/files.sysmon" | | | @@ -219,26 +219,27 @@ include "dev/sysmon/files.sysmon" |
219 | | | 219 | |
220 | # Attribute used by various things that need BPF's virtual machine | | 220 | # Attribute used by various things that need BPF's virtual machine |
221 | # | | 221 | # |
222 | define bpf_filter | | 222 | define bpf_filter |
223 | defparam opt_bpf.h BPF_BUFSIZE | | 223 | defparam opt_bpf.h BPF_BUFSIZE |
224 | | | 224 | |
225 | defflag opt_bpf.h BPFJIT | | 225 | defflag opt_bpf.h BPFJIT |
226 | | | 226 | |
227 | file net/bpfjit.c sljit & bpfjit | | 227 | file net/bpfjit.c sljit & bpfjit |
228 | | | 228 | |
229 | include "net80211/files.net80211" | | 229 | include "net80211/files.net80211" |
230 | include "netatalk/files.netatalk" | | 230 | include "netatalk/files.netatalk" |
231 | include "netbt/files.netbt" | | 231 | include "netbt/files.netbt" |
| | | 232 | include "netcan/files.netcan" |
232 | include "netinet/files.netinet" | | 233 | include "netinet/files.netinet" |
233 | include "netinet6/files.netinet6" | | 234 | include "netinet6/files.netinet6" |
234 | include "netipsec/files.netipsec" | | 235 | include "netipsec/files.netipsec" |
235 | include "netmpls/files.netmpls" | | 236 | include "netmpls/files.netmpls" |
236 | include "netnatm/files.netnatm" | | 237 | include "netnatm/files.netnatm" |
237 | include "netsmb/files.netsmb" | | 238 | include "netsmb/files.netsmb" |
238 | | | 239 | |
239 | include "net/npf/files.npf" | | 240 | include "net/npf/files.npf" |
240 | include "netinet/files.ipfilter" | | 241 | include "netinet/files.ipfilter" |
241 | include "net/files.pf" | | 242 | include "net/files.pf" |
242 | | | 243 | |
243 | obsolete defflag CCITT # obsolete | | 244 | obsolete defflag CCITT # obsolete |
244 | obsolete defflag HDLC # obsolete | | 245 | obsolete defflag HDLC # obsolete |
| @@ -1425,26 +1426,27 @@ defpseudo tun: ifnet | | | @@ -1425,26 +1426,27 @@ defpseudo tun: ifnet |
1425 | defpseudo vlan: ifnet, ether | | 1426 | defpseudo vlan: ifnet, ether |
1426 | defpseudo bridge: ifnet, ether | | 1427 | defpseudo bridge: ifnet, ether |
1427 | defpseudo bpfilter: ifnet, bpf_filter | | 1428 | defpseudo bpfilter: ifnet, bpf_filter |
1428 | defpseudo strip: ifnet | | 1429 | defpseudo strip: ifnet |
1429 | defpseudo gre: ifnet | | 1430 | defpseudo gre: ifnet |
1430 | defpseudo gif: ifnet | | 1431 | defpseudo gif: ifnet |
1431 | defpseudo faith: ifnet | | 1432 | defpseudo faith: ifnet |
1432 | defpseudo mpls: ifnet | | 1433 | defpseudo mpls: ifnet |
1433 | defpseudo srt: ifnet | | 1434 | defpseudo srt: ifnet |
1434 | defpseudo stf: ifnet | | 1435 | defpseudo stf: ifnet |
1435 | defpseudodev tap: ifnet, ether, arp | | 1436 | defpseudodev tap: ifnet, ether, arp |
1436 | defpseudo carp: ifnet, ether, arp | | 1437 | defpseudo carp: ifnet, ether, arp |
1437 | defpseudodev etherip: ifnet, ether, arp | | 1438 | defpseudodev etherip: ifnet, ether, arp |
| | | 1439 | defpseudo canloop: ifnet |
1438 | | | 1440 | |
1439 | defpseudo sequencer | | 1441 | defpseudo sequencer |
1440 | defpseudo clockctl | | 1442 | defpseudo clockctl |
1441 | | | 1443 | |
1442 | # | | 1444 | # |
1443 | # Accept filters. XXX should use another registration/initialization method. | | 1445 | # Accept filters. XXX should use another registration/initialization method. |
1444 | # | | 1446 | # |
1445 | defpseudo accf_data | | 1447 | defpseudo accf_data |
1446 | defpseudo accf_http | | 1448 | defpseudo accf_http |
1447 | | | 1449 | |
1448 | # ISDN userland pseudo devices | | 1450 | # ISDN userland pseudo devices |
1449 | # | | 1451 | # |
1450 | defpseudo isdntrc: isdndev, tty | | 1452 | defpseudo isdntrc: isdndev, tty |
--- src/sys/net/Attic/netisr.h 2015/05/25 08:29:01 1.44
+++ src/sys/net/Attic/netisr.h 2017/01/15 20:27:33 1.44.4.1
| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: netisr.h,v 1.44 2015/05/25 08:29:01 ozaki-r Exp $ */ | | 1 | /* $NetBSD: netisr.h,v 1.44.4.1 2017/01/15 20:27:33 bouyer Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1980, 1986, 1989, 1993 | | 4 | * Copyright (c) 1980, 1986, 1989, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. 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. |
| @@ -43,26 +43,27 @@ | | | @@ -43,26 +43,27 @@ |
43 | * at timeout time). | | 43 | * at timeout time). |
44 | * | | 44 | * |
45 | * The routine to request a network software interrupt, setsoftnet(), | | 45 | * The routine to request a network software interrupt, setsoftnet(), |
46 | * is defined in the machine-specific include files. | | 46 | * is defined in the machine-specific include files. |
47 | */ | | 47 | */ |
48 | | | 48 | |
49 | #if defined(_KERNEL) | | 49 | #if defined(_KERNEL) |
50 | | | 50 | |
51 | #if defined(_KERNEL_OPT) | | 51 | #if defined(_KERNEL_OPT) |
52 | #include "opt_inet.h" | | 52 | #include "opt_inet.h" |
53 | #include "opt_atalk.h" | | 53 | #include "opt_atalk.h" |
54 | #include "opt_mpls.h" | | 54 | #include "opt_mpls.h" |
55 | #include "opt_natm.h" | | 55 | #include "opt_natm.h" |
| | | 56 | #include "opt_can.h" |
56 | #include "arp.h" | | 57 | #include "arp.h" |
57 | #endif /* defined(_KERNEL_OPT) */ | | 58 | #endif /* defined(_KERNEL_OPT) */ |
58 | | | 59 | |
59 | #if !defined(_LOCORE) | | 60 | #if !defined(_LOCORE) |
60 | | | 61 | |
61 | /* XXX struct sockaddr defn for for if.h, if_arp.h */ | | 62 | /* XXX struct sockaddr defn for for if.h, if_arp.h */ |
62 | #include <sys/socket.h> | | 63 | #include <sys/socket.h> |
63 | | | 64 | |
64 | /* | | 65 | /* |
65 | * XXX IFNAMSIZE for if_ppp.h, natm.h; struct ifnet decl for in6.h, in.h; | | 66 | * XXX IFNAMSIZE for if_ppp.h, natm.h; struct ifnet decl for in6.h, in.h; |
66 | * XXX struct mbuf decl for in6.h, in.h, route.h (via in_var.h). | | 67 | * XXX struct mbuf decl for in6.h, in.h, route.h (via in_var.h). |
67 | */ | | 68 | */ |
68 | #include <net/if.h> | | 69 | #include <net/if.h> |
| @@ -80,40 +81,45 @@ | | | @@ -80,40 +81,45 @@ |
80 | # endif | | 81 | # endif |
81 | #include <netinet/ip6.h> | | 82 | #include <netinet/ip6.h> |
82 | #include <netinet6/ip6_var.h> | | 83 | #include <netinet6/ip6_var.h> |
83 | #endif | | 84 | #endif |
84 | #ifdef MPLS | | 85 | #ifdef MPLS |
85 | #include <netmpls/mpls_var.h> | | 86 | #include <netmpls/mpls_var.h> |
86 | #endif | | 87 | #endif |
87 | #ifdef NATM | | 88 | #ifdef NATM |
88 | #include <netnatm/natm.h> | | 89 | #include <netnatm/natm.h> |
89 | #endif | | 90 | #endif |
90 | #ifdef NETATALK | | 91 | #ifdef NETATALK |
91 | #include <netatalk/at_extern.h> | | 92 | #include <netatalk/at_extern.h> |
92 | #endif | | 93 | #endif |
| | | 94 | #ifdef CAN |
| | | 95 | #include <netcan/can.h> |
| | | 96 | #include <netcan/can_var.h> |
| | | 97 | #endif |
93 | | | 98 | |
94 | #endif /* !defined(_LOCORE) */ | | 99 | #endif /* !defined(_LOCORE) */ |
95 | #endif /* defined(_KERNEL) */ | | 100 | #endif /* defined(_KERNEL) */ |
96 | | | 101 | |
97 | | | 102 | |
98 | /* | | 103 | /* |
99 | * Each ``pup-level-1'' input queue has a bit in a ``netisr'' status | | 104 | * Each ``pup-level-1'' input queue has a bit in a ``netisr'' status |
100 | * word which is used to de-multiplex a single software | | 105 | * word which is used to de-multiplex a single software |
101 | * interrupt used for scheduling the network code to calls | | 106 | * interrupt used for scheduling the network code to calls |
102 | * on the lowest level routine of each protocol. | | 107 | * on the lowest level routine of each protocol. |
103 | */ | | 108 | */ |
104 | #define NETISR_IP 2 /* same as AF_INET */ | | 109 | #define NETISR_IP 2 /* same as AF_INET */ |
105 | #define NETISR_CCITT 10 /* same as AF_CCITT */ | | 110 | #define NETISR_CCITT 10 /* same as AF_CCITT */ |
106 | #define NETISR_ATALK 16 /* same as AF_APPLETALK */ | | 111 | #define NETISR_ATALK 16 /* same as AF_APPLETALK */ |
107 | #define NETISR_IPV6 24 /* same as AF_INET6 */ | | 112 | #define NETISR_IPV6 24 /* same as AF_INET6 */ |
108 | #define NETISR_ISDN 26 /* same as AF_E164 */ | | 113 | #define NETISR_ISDN 26 /* same as AF_E164 */ |
109 | #define NETISR_NATM 27 /* same as AF_NATM */ | | 114 | #define NETISR_NATM 27 /* same as AF_NATM */ |
110 | #define NETISR_ARP 28 /* same as AF_ARP */ | | 115 | #define NETISR_ARP 28 /* same as AF_ARP */ |
111 | #define NETISR_MPLS 33 /* same as AF_MPLS */ | | 116 | #define NETISR_MPLS 33 /* same as AF_MPLS */ |
| | | 117 | #define NETISR_CAN 35 /* same as AF_CAN */ |
112 | #define NETISR_MAX AF_MAX | | 118 | #define NETISR_MAX AF_MAX |
113 | | | 119 | |
114 | #if !defined(_LOCORE) && defined(_KERNEL) | | 120 | #if !defined(_LOCORE) && defined(_KERNEL) |
115 | /* XXX Legacy netisr support. */ | | 121 | /* XXX Legacy netisr support. */ |
116 | void schednetisr(int); | | 122 | void schednetisr(int); |
117 | #endif | | 123 | #endif |
118 | | | 124 | |
119 | #endif /* !_NET_NETISR_H_ */ | | 125 | #endif /* !_NET_NETISR_H_ */ |
--- src/sys/net/Attic/netisr_dispatch.h 2014/06/05 23:48:16 1.18
+++ src/sys/net/Attic/netisr_dispatch.h 2017/01/15 20:27:33 1.18.12.1
| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: netisr_dispatch.h,v 1.18 2014/06/05 23:48:16 rmind Exp $ */ | | 1 | /* $NetBSD: netisr_dispatch.h,v 1.18.12.1 2017/01/15 20:27:33 bouyer Exp $ */ |
2 | | | 2 | |
3 | #ifndef _NET_NETISR_DISPATCH_H_ | | 3 | #ifndef _NET_NETISR_DISPATCH_H_ |
4 | #define _NET_NETISR_DISPATCH_H_ | | 4 | #define _NET_NETISR_DISPATCH_H_ |
5 | | | 5 | |
6 | /* | | 6 | /* |
7 | * netisr_dispatch: This file is included by the | | 7 | * netisr_dispatch: This file is included by the |
8 | * machine dependent softnet function. The | | 8 | * machine dependent softnet function. The |
9 | * DONETISR macro should be set before including | | 9 | * DONETISR macro should be set before including |
10 | * this file. i.e.: | | 10 | * this file. i.e.: |
11 | * | | 11 | * |
12 | * softintr() { | | 12 | * softintr() { |
13 | * ...do setup stuff... | | 13 | * ...do setup stuff... |
14 | * #define DONETISR(bit, fn) do { ... } while (0) | | 14 | * #define DONETISR(bit, fn) do { ... } while (0) |
| @@ -31,15 +31,18 @@ | | | @@ -31,15 +31,18 @@ |
31 | #if NARP > 0 | | 31 | #if NARP > 0 |
32 | DONETISR(NETISR_ARP,arpintr); | | 32 | DONETISR(NETISR_ARP,arpintr); |
33 | #endif | | 33 | #endif |
34 | #endif | | 34 | #endif |
35 | #ifdef NETATALK | | 35 | #ifdef NETATALK |
36 | DONETISR(NETISR_ATALK,atintr); | | 36 | DONETISR(NETISR_ATALK,atintr); |
37 | #endif | | 37 | #endif |
38 | #ifdef MPLS | | 38 | #ifdef MPLS |
39 | DONETISR(NETISR_MPLS,mplsintr); | | 39 | DONETISR(NETISR_MPLS,mplsintr); |
40 | #endif | | 40 | #endif |
41 | #ifdef NATM | | 41 | #ifdef NATM |
42 | DONETISR(NETISR_NATM,natmintr); | | 42 | DONETISR(NETISR_NATM,natmintr); |
43 | #endif | | 43 | #endif |
| | | 44 | #ifdef CAN |
| | | 45 | DONETISR(NETISR_CAN,canintr); |
| | | 46 | #endif |
44 | | | 47 | |
45 | #endif /* !_NET_NETISR_DISPATCH_H_ */ | | 48 | #endif /* !_NET_NETISR_DISPATCH_H_ */ |
# $NetBSD: Makefile,v 1.1.2.1 2017/01/15 20:27:33 bouyer Exp $
KDIR= /sys/netcan
INCSDIR= /usr/include/netcan
INCS= can.h
.include <bsd.kinc.mk>
/* $NetBSD: can.c,v 1.1.2.1 2017/01/15 20:27:33 bouyer Exp $ */
/*-
* Copyright (c) 2003, 2017 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Robert Swindells and Manuel Bouyer
*
* 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.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: can.c,v 1.1.2.1 2017/01/15 20:27:33 bouyer Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/mbuf.h>
#include <sys/ioctl.h>
#include <sys/protosw.h>
#include <sys/errno.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/proc.h>
#include <sys/kauth.h>
#include <net/if.h>
#include <net/netisr.h>
#include <net/route.h>
#include <netcan/can.h>
#include <netcan/can_pcb.h>
#include <netcan/can_var.h>
struct canpcb canpcb;
#if 0
struct canpcb canrawpcb;
#endif
struct canpcbtable cbtable;
struct ifqueue canintrq;
int canqmaxlen = IFQ_MAXLEN;
int can_copy_output = 0;
int can_output_cnt = 0;
struct mbuf *can_lastout;
int can_sendspace = 4096; /* really max datagram size */
int can_recvspace = 40 * (1024 + sizeof(struct sockaddr_can));
/* 40 1K datagrams */
#ifndef CANHASHSIZE
#define CANHASHSIZE 128
#endif
int canhashsize = CANHASHSIZE;
static int can_output(struct mbuf *, struct canpcb *);
static int can_control(struct socket *, u_long, void *, struct ifnet *);
void
can_init(void)
{
canintrq.ifq_maxlen = canqmaxlen;
IFQ_LOCK_INIT(&canintrq);
can_pcbinit(&cbtable, canhashsize, canhashsize);
}
/*
* Generic control operations (ioctl's).
*/
/* ARGSUSED */
static int
can_control(struct socket *so, u_long cmd, void *data, struct ifnet *ifp)
{
#if 0
struct can_ifreq *cfr = (struct can_ifreq *)data;
int error = 0;
#endif
switch (cmd) {
default:
if (ifp == 0 || ifp->if_ioctl == 0)
return (EOPNOTSUPP);
return ((*ifp->if_ioctl)(ifp, cmd, data));
}
return (0);
}
static int
can_purgeif(struct socket *so, struct ifnet *ifp)
{
return 0;
}
static int
can_output(struct mbuf *m, struct canpcb *canp)
{
struct ifnet *ifp;
int error = 0;
if (canp == 0) {
printf("can_output: no pcb\n");
error = EINVAL;
goto done;
}
ifp = canp->canp_ifp;
if (ifp == 0) {
error = EDESTADDRREQ;
goto done;
}
if (m->m_len <= ifp->if_mtu) {
can_output_cnt++;
error = (*ifp->if_output)(ifp, m, NULL, 0);
goto done;
} else error = EMSGSIZE;
m_freem(m);
done:
return (error);
}
/*
* Process a received CAN frame
* the packet is in the mbuf chain m with
* the CAN header.
*/
void
can_input(struct ifnet *ifp, struct mbuf *m)
{
struct ifqueue *inq;
if ((ifp->if_flags & IFF_UP) == 0) {
m_freem(m);
return;
}
inq = &canintrq;
IFQ_LOCK(inq);
if (IF_QFULL(inq)) {
IF_DROP(inq);
IFQ_UNLOCK(inq);
m_freem(m);
} else {
IF_ENQUEUE(inq, m);
IFQ_UNLOCK(inq);
schednetisr(NETISR_CAN);
ifp->if_ipackets++;
ifp->if_ibytes += m->m_pkthdr.len;
}
}
void
canintr(void)
{
int rcv_ifindex;
struct mbuf *m;
struct sockaddr_can from;
struct canpcb *canp;
mutex_enter(softnet_lock);
for (;;) {
IFQ_LOCK(&canintrq);
IF_DEQUEUE(&canintrq, m);
IFQ_UNLOCK(&canintrq);
if (m == 0) /* no more queued packets */
break;
memset(&from, 0, sizeof(struct sockaddr_can));
rcv_ifindex = m->m_pkthdr.rcvif_index;
#if 0
m_claim(m, &can_rx_mowner);
#endif
from.can_ifindex = rcv_ifindex;
from.can_len = sizeof(struct sockaddr_can);
from.can_family = AF_CAN;
TAILQ_FOREACH(canp, &cbtable.canpt_queue, canp_queue) {
struct mbuf *mc;
if (canp->canp_ifp != NULL &&
canp->canp_ifp->if_index != rcv_ifindex) {
continue;
}
if (TAILQ_NEXT(canp, canp_queue) != NULL) {
/*
* we can't be sure we won't need
* the original mbuf later so copy
*/
mc = m_copym(m, 0, M_COPYALL, M_NOWAIT);
if (mc == NULL) {
/* deliver this mbuf and abort */
mc = m;
m = NULL;
}
} else {
mc = m;
m = NULL;
}
if (sbappendaddr(&canp->canp_socket->so_rcv,
(struct sockaddr *) &from, mc,
(struct mbuf *) 0) == 0) {
m_freem(mc);
} else
sorwakeup(canp->canp_socket);
if (m == NULL)
break;
}
/* If it didn't go anywhere just delete it */
if (m) {
m_freem(m);
}
}
mutex_exit(softnet_lock);
}
static int
can_attach(struct socket *so, int proto)
{
/*struct canpcb *canp;*/
int error;
KASSERT(sotocanpcb(so) == NULL);
/* Assign the lock (must happen even if we will error out). */
sosetlock(so);
#ifdef MBUFTRACE
so->so_mowner = &can_mowner;
so->so_rcv.sb_mowner = &can_rx_mowner;
so->so_snd.sb_mowner = &can_tx_mowner;
#endif
if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
error = soreserve(so, can_sendspace, can_recvspace);
if (error) {
return error;
}
}
error = can_pcballoc(so, &cbtable);
if (error) {
return error;
}
/*canp = sotocanpcb(so);*/
KASSERT(solocked(so));
return error;
}
static void
can_detach(struct socket *so)
{
struct canpcb *canp;
KASSERT(solocked(so));
canp = sotocanpcb(so);
can_pcbdetach(canp);
}
static int
can_accept(struct socket *so, struct sockaddr *nam)
{
KASSERT(solocked(so));
panic("can_accept");
return EOPNOTSUPP;
}
static int
can_bind(struct socket *so, struct sockaddr *nam, struct lwp *l)
{
struct canpcb *canp = sotocanpcb(so);
struct sockaddr_can *scan = (struct sockaddr_can *)nam;
KASSERT(solocked(so));
KASSERT(nam != NULL);
return can_pcbbind(canp, scan, l);
}
static int
can_listen(struct socket *so, struct lwp *l)
{
KASSERT(solocked(so));
return EOPNOTSUPP;
}
static int
can_connect(struct socket *so, struct sockaddr *nam, struct lwp *l)
{
struct canpcb *canp = sotocanpcb(so);
int error = 0;
KASSERT(solocked(so));
KASSERT(canp != NULL);
KASSERT(nam != NULL);
error = can_pcbconnect(canp, (struct sockaddr_can *)nam);
if (! error)
soisconnected(so);
return error;
}
static int
can_connect2(struct socket *so, struct socket *so2)
{
KASSERT(solocked(so));
return EOPNOTSUPP;
}
static int
can_disconnect(struct socket *so)
{
struct canpcb *canp = sotocanpcb(so);
KASSERT(solocked(so));
KASSERT(canp != NULL);
/*soisdisconnected(so);*/
so->so_state &= ~SS_ISCONNECTED; /* XXX */
can_pcbdisconnect(canp);
can_pcbstate(canp, CANP_BOUND); /* XXX */
return 0;
}
static int
can_shutdown(struct socket *so)
{
KASSERT(solocked(so));
socantsendmore(so);
return 0;
}
static int
can_abort(struct socket *so)
{
KASSERT(solocked(so));
panic("can_abort");
return EOPNOTSUPP;
}
static int
can_ioctl(struct socket *so, u_long cmd, void *nam, struct ifnet *ifp)
{
return can_control(so, cmd, nam, ifp);
}
static int
can_stat(struct socket *so, struct stat *ub)
{
KASSERT(solocked(so));
/* stat: don't bother with a blocksize. */
return 0;
}
static int
can_peeraddr(struct socket *so, struct sockaddr *nam)
{
KASSERT(solocked(so));
KASSERT(sotocanpcb(so) != NULL);
KASSERT(nam != NULL);
return EOPNOTSUPP;
}
static int
can_sockaddr(struct socket *so, struct sockaddr *nam)
{
KASSERT(solocked(so));
KASSERT(sotocanpcb(so) != NULL);
KASSERT(nam != NULL);
can_setsockaddr(sotocanpcb(so), (struct sockaddr_can *)nam);
return 0;
}
static int
can_rcvd(struct socket *so, int flags, struct lwp *l)
{
KASSERT(solocked(so));
return EOPNOTSUPP;
}
static int
can_recvoob(struct socket *so, struct mbuf *m, int flags)
{
KASSERT(solocked(so));
return EOPNOTSUPP;
}
static int
can_send(struct socket *so, struct mbuf *m, struct sockaddr *nam,
struct mbuf *control, struct lwp *l)
{
struct canpcb *canp = sotocanpcb(so);
int error = 0;
int s;
if (control && control->m_len) {
return EINVAL;
}
if (nam) {
if ((so->so_state & SS_ISCONNECTED) != 0) {
return EISCONN;
}
s = splnet();
error = can_pcbbind(canp, (struct sockaddr_can *)nam, l);
if (error) {
splx(s);
return error;
}
} else {
if ((so->so_state & SS_ISCONNECTED) == 0) {
return EDESTADDRREQ;
}
}
error = can_output(m, canp);
if (nam) {
struct sockaddr_can lscan;
memset(&lscan, 0, sizeof(lscan));
lscan.can_family = AF_CAN;
lscan.can_len = sizeof(lscan);
can_pcbbind(canp, &lscan, l);
}
return error;
}
static int
can_sendoob(struct socket *so, struct mbuf *m, struct mbuf *control)
{
KASSERT(solocked(so));
m_freem(m);
m_freem(control);
return EOPNOTSUPP;
}
#if 0
int
can_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
struct mbuf *control, struct lwp *l)
{
struct canpcb *canp;
int s;
int error = 0;
if (req == PRU_CONTROL)
return (can_control(so, (long)m, nam,
(struct ifnet *)control));
if (req == PRU_PURGEIF) {
#if 0
can_pcbpurgeif0(&udbtable, (struct ifnet *)control);
can_purgeif((struct ifnet *)control);
can_pcbpurgeif(&udbtable, (struct ifnet *)control);
#endif
return (0);
}
s = splsoftnet();
canp = sotocanpcb(so);
#ifdef DIAGNOSTIC
if (req != PRU_SEND && req != PRU_SENDOOB && control)
panic("can_usrreq: unexpected control mbuf");
#endif
if (canp == 0 && req != PRU_ATTACH) {
printf("can_usrreq: no pcb %p %d\n", canp, req);
error = EINVAL;
goto release;
}
/*
* Note: need to block can_input while changing
* the can pcb queue and/or pcb addresses.
*/
switch (req) {
case PRU_ATTACH:
if (canp != 0) {
error = EISCONN;
break;
}
#ifdef MBUFTRACE
so->so_mowner = &can_mowner;
so->so_rcv.sb_mowner = &can_rx_mowner;
so->so_snd.sb_mowner = &can_tx_mowner;
#endif
if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
error = soreserve(so, can_sendspace, can_recvspace);
if (error)
break;
}
error = can_pcballoc(so, &cbtable);
if (error)
break;
canp = sotocanpcb(so);
#if 0
inp->inp_ip.ip_ttl = ip_defttl;
#endif
break;
case PRU_DETACH:
can_pcbdetach(canp);
break;
case PRU_BIND:
error = can_pcbbind(canp, nam, l);
break;
case PRU_LISTEN:
error = EOPNOTSUPP;
break;
case PRU_CONNECT:
error = can_pcbconnect(canp, nam);
if (error)
break;
soisconnected(so);
break;
case PRU_CONNECT2:
error = EOPNOTSUPP;
break;
case PRU_DISCONNECT:
/*soisdisconnected(so);*/
so->so_state &= ~SS_ISCONNECTED; /* XXX */
can_pcbdisconnect(canp);
can_pcbstate(canp, CANP_BOUND); /* XXX */
break;
case PRU_SHUTDOWN:
socantsendmore(so);
break;
case PRU_RCVD:
error = EOPNOTSUPP;
break;
case PRU_SEND:
break;
case PRU_SENSE:
/*
* stat: don't bother with a blocksize.
*/
splx(s);
return (0);
case PRU_RCVOOB:
error = EOPNOTSUPP;
break;
case PRU_SENDOOB:
m_freem(control);
m_freem(m);
error = EOPNOTSUPP;
break;
case PRU_SOCKADDR:
break;
case PRU_PEERADDR:
error = EOPNOTSUPP;
break;
default:
panic("can_usrreq");
}
release:
splx(s);
return (error);
}
#endif
#if 0
static void
can_notify(struct canpcb *canp, int errno)
{
canp->canp_socket->so_error = errno;
sorwakeup(canp->canp_socket);
sowwakeup(canp->canp_socket);
}
void *
can_ctlinput(int cmd, struct sockaddr *sa, void *v)
{
struct ip *ip = v;
struct canhdr *uh;
void (*notify) __P((struct inpcb *, int)) = can_notify;
int errno;
if (sa->sa_family != AF_CAN
|| sa->sa_len != sizeof(struct sockaddr_can))
return NULL;
if ((unsigned)cmd >= PRC_NCMDS)
return NULL;
errno = inetctlerrmap[cmd];
if (PRC_IS_REDIRECT(cmd))
notify = in_rtchange, ip = 0;
else if (cmd == PRC_HOSTDEAD)
ip = 0;
else if (errno == 0)
return NULL;
if (ip) {
uh = (struct canhdr *)((caddr_t)ip + (ip->ip_hl << 2));
in_pcbnotify(&udbtable, satosin(sa)->sin_addr, uh->uh_dport,
ip->ip_src, uh->uh_sport, errno, notify);
/* XXX mapped address case */
} else
can_pcbnotifyall(&cbtable, satoscan(sa)->scan_addr, errno,
notify);
return NULL;
}
#endif
PR_WRAP_USRREQS(can)
#define can_attach can_attach_wrapper
#define can_detach can_detach_wrapper
#define can_accept can_accept_wrapper
#define can_bind can_bind_wrapper
#define can_listen can_listen_wrapper
#define can_connect can_connect_wrapper
#define can_connect2 can_connect2_wrapper
#define can_disconnect can_disconnect_wrapper
#define can_shutdown can_shutdown_wrapper
#define can_abort can_abort_wrapper
#define can_ioctl can_ioctl_wrapper
#define can_stat can_stat_wrapper
#define can_peeraddr can_peeraddr_wrapper
#define can_sockaddr can_sockaddr_wrapper
#define can_rcvd can_rcvd_wrapper
#define can_recvoob can_recvoob_wrapper
#define can_send can_send_wrapper
#define can_sendoob can_sendoob_wrapper
#define can_purgeif can_purgeif_wrapper
const struct pr_usrreqs can_usrreqs = {
.pr_attach = can_attach,
.pr_detach = can_detach,
.pr_accept = can_accept,
.pr_bind = can_bind,
.pr_listen = can_listen,
.pr_connect = can_connect,
.pr_connect2 = can_connect2,
.pr_disconnect = can_disconnect,
.pr_shutdown = can_shutdown,
.pr_abort = can_abort,
.pr_ioctl = can_ioctl,
.pr_stat = can_stat,
.pr_peeraddr = can_peeraddr,
.pr_sockaddr = can_sockaddr,
.pr_rcvd = can_rcvd,
.pr_recvoob = can_recvoob,
.pr_send = can_send,
.pr_sendoob = can_sendoob,
.pr_purgeif = can_purgeif,
};
/* $NetBSD: can.h,v 1.1.2.1 2017/01/15 20:27:33 bouyer Exp $ */
/*-
* Copyright (c) 2003, 2017 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Robert Swindells and Manuel Bouyer
*
* 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.
*/
#ifndef _NETCAN_CAN_H
#define _NETCAN_CAN_H
#include <sys/featuretest.h>
#include <machine/int_types.h>
/* Definitions compatible (as much as possible) with socketCAN */
/*
* CAN id structure
* bits 0-28 : CAN identifier (11/29 bits, see bit 31)
* bit2 29-31 : see below
*/
typedef uint32_t canid_t;
typedef uint32_t can_err_mask_t;
/* canid_t bits 29-31 descriptions */
#define CAN_EFF_FLAG 0x80000000U /* extended frame format */
#define CAN_RTR_FLAG 0x40000000U /* remote transmission request */
#define CAN_ERR_FLAG 0x20000000U /* error message frame */
/* valid bits in CAN ID for frame formats */
#define CAN_SFF_MASK 0x000007FFU /* standard frame format (SFF) */
#define CAN_EFF_MASK 0x1FFFFFFFU /* extended frame format (EFF) */
#define CAN_ERR_MASK 0x1FFFFFFFU /* error frame format */
/* CAN payload length and DLC definitions according to ISO 11898-1 */
#define CAN_MAX_DLC 8
#define CAN_MAX_DLEN 8
/* CAN frame */
struct can_frame {
canid_t can_id; /* ID + EFF/RTR/ERR flags */
uint8_t can_dlc; /* frame payload length in byte (0 .. CAN_MAX_DLEN) */
uint8_t __pad;
uint8_t __res0;
uint8_t __res1;
uint8_t data[CAN_MAX_DLEN];
};
#define CAN_MTU (sizeof(struct can_frame))
/* protocols */
#define CAN_RAW 1 /* RAW sockets */
#define CAN_NPROTO 2
#define SOL_CAN_BASE 100
/*
* Socket address, CAN style
*/
struct sockaddr_can {
u_int8_t can_len;
sa_family_t can_family;
int can_ifindex;
union {
/* transport protocol class address information (e.g. ISOTP) */
struct { canid_t rx_id, tx_id; } tp;
/* reserved for future CAN protocols address information */
} can_addr;
};
/*
* Options for use with [gs]etsockopt
* First word of comment is data type; bool is stored in int.
*/
#define CAN_RAW_FILTER 1 /* struct can_filter: set filter */
/*
* CAN ID based filter
* checks received can_id & can_filter.can_mask against
* can_filter.can_id & can_filter.can_mask
* valid flags for can_id:
* CAN_INV_FILTER: invert filter
* valid flags for can_mask:
* CAN_ERR_FLAG: filter for error message frames
*/
struct can_filter {
canid_t can_id;
canid_t can_mask;
};
#define CAN_INV_FILTER 0x20000000U
#ifdef _NETBSD_SOURCE
/* CAN sockets ioctl */
#define SIOCSCANBAUD _IOW('i', 134, int) /* set interface speed */
#define SIOCGCANBAUD _IOR('i', 135, int) /* get interface speed */
#ifdef _KERNEL
#define satoscan(sa) ((struct sockaddr_can *)(sa))
#define scantosa(scan) ((struct sockaddr *)(scan))
#endif /* _KERNEL */
#endif /* _NETBSD_SOURCE */
#endif /* _NETCAN_CAN_H */
/* $NetBSD: can_pcb.c,v 1.1.2.1 2017/01/15 20:27:33 bouyer Exp $ */
/*-
* Copyright (c) 2003, 2017 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Robert Swindells and Manuel Bouyer
*
* 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.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: can_pcb.c,v 1.1.2.1 2017/01/15 20:27:33 bouyer Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/ioctl.h>
#include <sys/errno.h>
#include <sys/time.h>
#include <sys/pool.h>
#include <sys/proc.h>
#include <net/if.h>
#include <net/route.h>
#include <netcan/can.h>
#include <netcan/can_var.h>
#include <netcan/can_pcb.h>
#define CANPCBHASH_BIND(table, ifindex) \
&(table)->canpt_bindhashtbl[ \
(ifindex) & (table)->canpt_bindhash]
#define CANPCBHASH_CONNECT(table, ifindex) \
&(table)->canpt_connecthashtbl[ \
(ifindex) & (table)->canpt_bindhash]
struct pool canpcb_pool;
void
can_pcbinit(struct canpcbtable *table, int bindhashsize, int connecthashsize)
{
static int canpcb_pool_initialized;
if (canpcb_pool_initialized == 0) {
pool_init(&canpcb_pool, sizeof(struct canpcb), 0, 0, 0,
"canpcbpl", NULL, IPL_SOFTNET);
canpcb_pool_initialized = 1;
}
TAILQ_INIT(&table->canpt_queue);
table->canpt_bindhashtbl = hashinit(bindhashsize, HASH_LIST, true,
&table->canpt_bindhash);
table->canpt_connecthashtbl = hashinit(connecthashsize, HASH_LIST,
true, &table->canpt_connecthash);
}
int
can_pcballoc(struct socket *so, void *v)
{
struct canpcbtable *table = v;
struct canpcb *canp;
int s;
s = splnet();
canp = pool_get(&canpcb_pool, PR_NOWAIT);
splx(s);
if (canp == NULL)
return (ENOBUFS);
memset(canp, 0, sizeof(*canp));
canp->canp_table = table;
canp->canp_socket = so;
so->so_pcb = canp;
s = splnet();
TAILQ_INSERT_HEAD(&table->canpt_queue, canp, canp_queue);
can_pcbstate(canp, CANP_ATTACHED);
splx(s);
return (0);
}
int
can_pcbbind(void *v, struct sockaddr_can *scan, struct lwp *l)
{
struct canpcb *canp = v;
if (scan->can_family != AF_CAN)
return (EAFNOSUPPORT);
if (scan->can_ifindex != 0) {
canp->canp_ifp = if_byindex(scan->can_ifindex);
if (canp->canp_ifp == NULL)
return (EADDRNOTAVAIL);
soisconnected(canp->canp_socket);
} else {
canp->canp_ifp = NULL;
canp->canp_socket->so_state &= ~SS_ISCONNECTED; /* XXX */
}
can_pcbstate(canp, CANP_BOUND);
return 0;
}
/*
* Connect from a socket to a specified address.
*/
int
can_pcbconnect(void *v, struct sockaddr_can *scan)
{
#if 0
struct canpcb *canp = v;
struct sockaddr_can *ifaddr = NULL;
int error;
#endif
if (scan->can_family != AF_CAN)
return (EAFNOSUPPORT);
#if 0
memcpy(&canp->canp_dst, scan, sizeof(struct sockaddr_can));
can_pcbstate(canp, CANP_CONNECTED);
return 0;
#endif
return EOPNOTSUPP;
}
void
can_pcbdisconnect(void *v)
{
struct canpcb *canp = v;
can_pcbstate(canp, CANP_BOUND);
if (canp->canp_socket->so_state & SS_NOFDREF)
can_pcbdetach(canp);
}
void
can_pcbdetach(void *v)
{
struct canpcb *canp = v;
struct socket *so = canp->canp_socket;
int s;
KASSERT(mutex_owned(softnet_lock));
so->so_pcb = NULL;
s = splnet();
can_pcbstate(canp, CANP_ATTACHED);
TAILQ_REMOVE(&canp->canp_table->canpt_queue, canp, canp_queue);
splx(s);
sofree(so); /* sofree drops the lock */
pool_put(&canpcb_pool, canp);
mutex_enter(softnet_lock);
}
void
can_setsockaddr(struct canpcb *canp, struct sockaddr_can *scan)
{
memset(scan, 0, sizeof (*scan));
scan->can_family = AF_CAN;
scan->can_len = sizeof(*scan);
scan->can_ifindex = canp->canp_ifp->if_index;
}
#if 0
/*
* Pass some notification to all connections of a protocol
* associated with address dst. The local address and/or port numbers
* may be specified to limit the search. The "usual action" will be
* taken, depending on the ctlinput cmd. The caller must filter any
* cmds that are uninteresting (e.g., no error in the map).
* Call the protocol specific routine (if any) to report
* any errors for each matching socket.
*
* Must be called at splsoftnet.
*/
int
can_pcbnotify(struct canpcbtable *table, u_int32_t faddr, u_int32_t laddr,
int errno, void (*notify)(struct canpcb *, int))
{
struct canpcbhead *head;
struct canpcb *canp, *ncanp;
int nmatch;
if (faddr == 0 || notify == 0)
return (0);
nmatch = 0;
head = CANPCBHASH_CONNECT(table, faddr, laddr);
for (canp = LIST_FIRST(head); canp != NULL; canp = ncanp) {
ncanp = LIST_NEXT(canp, canp_hash);
if (canp->canp_faddr == faddr &&
canp->canp_laddr == laddr) {
(*notify)(canp, errno);
nmatch++;
}
}
return (nmatch);
}
void
can_pcbnotifyall(struct canpcbtable *table, u_int32_t faddr, int errno,
void (*notify)(struct canpcb *, int))
{
struct canpcb *canp, *ncanp;
if (faddr == 0 || notify == 0)
return;
TAILQ_FOREACH_SAFE(canp, &table->canpt_queue, canp_queue, ncanp) {
if (canp->canp_faddr == faddr)
(*notify)(canp, errno);
}
}
#endif
#if 0
void
can_pcbpurgeif0(struct canpcbtable *table, struct ifnet *ifp)
{
struct canpcb *canp, *ncanp;
struct ip_moptions *imo;
int i, gap;
}
void
can_pcbpurgeif(struct canpcbtable *table, struct ifnet *ifp)
{
struct canpcb *canp, *ncanp;
for (canp = CIRCLEQ_FIRST(&table->canpt_queue);
canp != (void *)&table->canpt_queue;
canp = ncanp) {
ncanp = CIRCLEQ_NEXT(canp, canp_queue);
}
}
#endif
void
can_pcbstate(struct canpcb *canp, int state)
{
int ifindex = canp->canp_ifp ? canp->canp_ifp->if_index : 0;
if (canp->canp_state > CANP_ATTACHED)
LIST_REMOVE(canp, canp_hash);
switch (state) {
case CANP_BOUND:
LIST_INSERT_HEAD(CANPCBHASH_BIND(canp->canp_table,
ifindex), canp, canp_hash);
break;
case CANP_CONNECTED:
LIST_INSERT_HEAD(CANPCBHASH_CONNECT(canp->canp_table,
ifindex), canp, canp_hash);
break;
}
canp->canp_state = state;
}
/* $NetBSD: can_pcb.h,v 1.1.2.1 2017/01/15 20:27:33 bouyer Exp $ */
/*-
* Copyright (c) 2003, 2017 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Robert Swindells and Manuel Bouyer
*
* 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.
*/
#ifndef _NETCAN_CAN_PCB_H_
#define _NETCAN_CAN_PCB_H_
#include <sys/queue.h>
/*
* Common structure pcb for can protocol implementation.
* Here are stored pointers to local and foreign host table
* entries, local and foreign socket numbers, and pointers
* up (to a socket structure) and down (to a protocol-specific)
* control block.
*/
struct canpcbpolicy;
struct canpcb {
LIST_ENTRY(canpcb) canp_hash;
LIST_ENTRY(canpcb) canp_lhash;
TAILQ_ENTRY(canpcb) canp_queue;
int canp_state;
struct socket *canp_socket; /* back pointer to socket */
struct ifnet *canp_ifp;
struct canpcbtable *canp_table;
};
LIST_HEAD(canpcbhead, canpcb);
#define canp_faddr canp_dst.scan_addr
TAILQ_HEAD(canpcbqueue, canpcb);
struct canpcbtable {
struct canpcbqueue canpt_queue;
struct canpcbhead *canpt_bindhashtbl;
struct canpcbhead *canpt_connecthashtbl;
u_long canpt_bindhash;
u_long canpt_connecthash;
};
/* states in inp_state: */
#define CANP_ATTACHED 0
#define CANP_BOUND 1
#define CANP_CONNECTED 2
/* flags in inp_flags: */
#define sotocanpcb(so) ((struct canpcb *)(so)->so_pcb)
#ifdef _KERNEL
void can_losing(struct canpcb *);
int can_pcballoc (struct socket *, void *);
int can_pcbbind(void *, struct sockaddr_can *, struct lwp *);
int can_pcbconnect(void *, struct sockaddr_can *);
void can_pcbdetach(void *);
void can_pcbdisconnect(void *);
void can_pcbinit(struct canpcbtable *, int, int);
int can_pcbnotify(struct canpcbtable *, u_int32_t,
u_int32_t, int, void (*)(struct canpcb *, int));
void can_pcbnotifyall(struct canpcbtable *, u_int32_t, int,
void (*)(struct canpcb *, int));
void can_pcbpurgeif0(struct canpcbtable *, struct ifnet *);
void can_pcbpurgeif(struct canpcbtable *, struct ifnet *);
void can_pcbstate(struct canpcb *, int);
void can_setsockaddr(struct canpcb *, struct sockaddr_can *);
#endif
#endif /* _NETCAN_CAN_PCB_H_ */
/* $NetBSD: can_proto.c,v 1.1.2.1 2017/01/15 20:27:33 bouyer Exp $ */
/*-
* Copyright (c) 2003, 2017 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Robert Swindells and Manuel Bouyer
*
* 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.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: can_proto.c,v 1.1.2.1 2017/01/15 20:27:33 bouyer Exp $");
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/protosw.h>
#include <sys/domain.h>
#include <sys/mbuf.h>
#include <net/if.h>
#include <net/radix.h>
#include <net/route.h>
/*
* CAN protocol family
*/
#include <netcan/can.h>
#include <netcan/can_var.h>
DOMAIN_DEFINE(candomain); /* forward declare and add to link set */
const struct protosw cansw[] = {
{
.pr_type = SOCK_RAW,
.pr_domain = &candomain,
.pr_init = can_init,
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_usrreqs = &can_usrreqs,
}
};
struct domain candomain = {
.dom_family = PF_CAN,
.dom_name = "can",
.dom_init = can_init,
.dom_externalize = NULL, .dom_dispose = NULL,
.dom_protosw = cansw,
.dom_protoswNPROTOSW = &cansw[__arraycount(cansw)],
.dom_ifqueues = { &canintrq, NULL },
.dom_link = { NULL },
.dom_mowner = MOWNER_INIT("",""),
.dom_sa_cmpofs = offsetof(struct sockaddr_can, can_ifindex),
.dom_sa_cmplen = sizeof(int)
};
/* $NetBSD: can_var.h,v 1.1.2.1 2017/01/15 20:27:33 bouyer Exp $ */
/*-
* Copyright (c) 2003, 2017 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Robert Swindells and Manuel Bouyer
*
* 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.
*/
#ifndef _NETCAN_CAN_VAR_H_
#define _NETCAN_CAN_VAR_H_
#include <sys/queue.h>
struct can_ifreq {
char cfr_name[IFNAMSIZ]; /* if name, e.g. "sja0" */
};
#ifdef _KERNEL
extern struct ifqueue canintrq;
extern struct domain candomain;
extern const struct pr_usrreqs can_usrreqs;
void can_input(struct ifnet *, struct mbuf *);
void *can_ctlinput(int, struct sockaddr *, void *);
int can_ctloutput(int, struct socket *, int, int, struct mbuf **);
void can_init(void);
void canintr(void);
#endif
#endif
# $NetBSD: files.netcan,v 1.1.2.1 2017/01/15 20:27:33 bouyer Exp $
defflag opt_can.h CAN # ISO-15765 CAN network stack
file netcan/can.c can
file netcan/can_proto.c can
file netcan/can_pcb.c can
file net/if_canloop.c canloop
/* $NetBSD: if_canloop.c,v 1.1.2.1 2017/01/15 20:27:33 bouyer Exp $ */
/*-
* Copyright (c) 2017 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Manuel Bouyer.
*
* 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.
*/
/*
* Loopback interface driver for the CAN protocol
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_canloop.c,v 1.1.2.1 2017/01/15 20:27:33 bouyer Exp $");
#ifdef _KERNEL_OPT
#include "opt_can.h"
#include "opt_net_mpsafe.h"
#endif
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/mbuf.h>
#include <sys/socket.h>
#include <sys/errno.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/device.h>
#include <sys/module.h>
#include <sys/cpu.h>
#include <net/if.h>
#include <net/if_types.h>
#include <net/netisr.h>
#ifdef CAN
#include <netcan/can.h>
#endif
#include <net/bpf.h>
void canloopattach(int);
void canloopinit(void);
static int canloop_clone_create(struct if_clone *, int);
static int canloop_clone_destroy(struct ifnet *);
static int canloop_ioctl(struct ifnet *, u_long, void *);
static int canloop_output(struct ifnet *,
struct mbuf *, const struct sockaddr *, const struct rtentry *);
static int canloop_count;
static struct if_clone canloop_cloner =
IF_CLONE_INITIALIZER("canlo", canloop_clone_create, canloop_clone_destroy);
void
canloopattach(int n)
{
/*
* Nothing to do here, initialization is handled by the
* module initialization code in canloopnit() below).
*/
}
void
canloopinit(void)
{
canloop_count = 0;
if_clone_attach(&canloop_cloner);
}
static int
canloopdetach(void)
{
if (canloop_count > 0)
return EBUSY;
if_clone_detach(&canloop_cloner);
return 0;
}
static int
canloop_clone_create(struct if_clone *ifc, int unit)
{
struct ifnet *ifp;
ifp = if_alloc(IFT_OTHER);
if_initname(ifp, ifc->ifc_name, unit);
ifp->if_mtu = sizeof(struct can_frame);
ifp->if_flags = IFF_LOOPBACK | IFF_RUNNING;
ifp->if_extflags = IFEF_OUTPUT_MPSAFE;
ifp->if_ioctl = canloop_ioctl;
ifp->if_output = canloop_output;
ifp->if_type = IFT_OTHER;
ifp->if_hdrlen = 0;
ifp->if_addrlen = 0;
ifp->if_dlt = DLT_CAN_SOCKETCAN;
IFQ_SET_READY(&ifp->if_snd);
if_attach(ifp);
if_alloc_sadl(ifp);
bpf_attach(ifp, DLT_CAN_SOCKETCAN, sizeof(u_int));
#ifdef MBUFTRACE
ifp->if_mowner = malloc(sizeof(struct mowner), M_DEVBUF,
M_WAITOK | M_ZERO);
strlcpy(ifp->if_mowner->mo_name, ifp->if_xname,
sizeof(ifp->if_mowner->mo_name));
MOWNER_ATTACH(ifp->if_mowner);
#endif
canloop_count++;
return (0);
}
static int
canloop_clone_destroy(struct ifnet *ifp)
{
#ifdef MBUFTRACE
MOWNER_DETACH(ifp->if_mowner);
free(ifp->if_mowner, M_DEVBUF);
#endif
bpf_detach(ifp);
if_detach(ifp);
if_free(ifp);
canloop_count--;
KASSERT(canloop_count >= 0);
return (0);
}
static int
canloop_output(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst,
const struct rtentry *rt)
{
int error = 0;
size_t pktlen;
MCLAIM(m, ifp->if_mowner);
KERNEL_LOCK(1, NULL);
if ((m->m_flags & M_PKTHDR) == 0)
panic("canloop_output: no header mbuf");
if (ifp->if_flags & IFF_LOOPBACK)
bpf_mtap_af(ifp, AF_CAN, m);
m_set_rcvif(m, ifp);
pktlen = m->m_pkthdr.len;
ifp->if_opackets++;
ifp->if_obytes += pktlen;
m_tag_delete_nonpersistent(m);
#ifdef CAN
can_input(ifp, m);
#else
printf("%s: can't handle CAN packet\n", ifp->if_xname);
m_freem(m);
error = EAFNOSUPPORT;
#endif
KERNEL_UNLOCK_ONE(NULL);
return error;
}
/*
* Process an ioctl request.
*/
/* ARGSUSED */
static int
canloop_ioctl(struct ifnet *ifp, u_long cmd, void *data)
{
struct ifreq *ifr = data;
int error = 0;
switch (cmd) {
case SIOCINITIFADDR:
error = EAFNOSUPPORT;
break;
case SIOCSIFMTU:
if ((unsigned)ifr->ifr_mtu != sizeof(struct can_frame))
error = EINVAL;
break;
case SIOCADDMULTI:
case SIOCDELMULTI:
error = EAFNOSUPPORT;
break;
default:
error = ifioctl_common(ifp, cmd, data);
}
return (error);
}
/*
* Module infrastructure
*/
#include "../net/if_module.h"
IF_MODULE(MODULE_CLASS_DRIVER, canloop, "")
--- src/sys/rump/include/opt/opt_rumpkernel.h 2016/04/15 01:35:26 1.5
+++ src/sys/rump/include/opt/opt_rumpkernel.h 2017/01/15 20:27:33 1.5.4.1
| @@ -1,33 +1,35 @@ | | | @@ -1,33 +1,35 @@ |
1 | /* $NetBSD: opt_rumpkernel.h,v 1.5 2016/04/15 01:35:26 ozaki-r Exp $ */ | | 1 | /* $NetBSD: opt_rumpkernel.h,v 1.5.4.1 2017/01/15 20:27:33 bouyer Exp $ */ |
2 | | | 2 | |
3 | #ifndef __NetBSD__ | | 3 | #ifndef __NetBSD__ |
4 | #define __NetBSD__ | | 4 | #define __NetBSD__ |
5 | #endif | | 5 | #endif |
6 | | | 6 | |
7 | #define _KERNEL 1 | | 7 | #define _KERNEL 1 |
8 | #define _MODULE 1 | | 8 | #define _MODULE 1 |
9 | | | 9 | |
10 | #define MODULAR 1 | | 10 | #define MODULAR 1 |
11 | #define MULTIPROCESSOR 1 | | 11 | #define MULTIPROCESSOR 1 |
12 | #define MAXUSERS 32 | | 12 | #define MAXUSERS 32 |
13 | | | 13 | |
14 | #define DEBUGPRINT | | 14 | #define DEBUGPRINT |
15 | | | 15 | |
16 | #define DEFCORENAME "rumpdump" | | 16 | #define DEFCORENAME "rumpdump" |
17 | #define DUMP_ON_PANIC 0 | | 17 | #define DUMP_ON_PANIC 0 |
18 | | | 18 | |
19 | #define INET 1 | | 19 | #define INET 1 |
20 | #define INET6 1 | | 20 | #define INET6 1 |
21 | #define GATEWAY 1 | | 21 | #define GATEWAY 1 |
22 | | | 22 | |
23 | #define MPLS 1 | | 23 | #define MPLS 1 |
24 | | | 24 | |
| | | 25 | #define CAN 1 |
| | | 26 | |
25 | #define SOSEND_NO_LOAN | | 27 | #define SOSEND_NO_LOAN |
26 | | | 28 | |
27 | #undef PIPE_SOCKETPAIR /* would need uipc_usrreq.c */ | | 29 | #undef PIPE_SOCKETPAIR /* would need uipc_usrreq.c */ |
28 | #define PIPE_NODIRECT | | 30 | #define PIPE_NODIRECT |
29 | | | 31 | |
30 | #define WSEMUL_NO_DUMB | | 32 | #define WSEMUL_NO_DUMB |
31 | #define WSEMUL_VT100 | | 33 | #define WSEMUL_VT100 |
32 | | | 34 | |
33 | #define PPPOE_SERVER | | 35 | #define PPPOE_SERVER |
--- src/sys/rump/include/rump/rumpdefs.h 2016/02/02 01:15:58 1.36
+++ src/sys/rump/include/rump/rumpdefs.h 2017/01/15 20:27:33 1.36.4.1
| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: rumpdefs.h,v 1.36 2016/02/02 01:15:58 pooka Exp $ */ | | 1 | /* $NetBSD: rumpdefs.h,v 1.36.4.1 2017/01/15 20:27:33 bouyer Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * AUTOMATICALLY GENERATED. DO NOT EDIT. | | 4 | * AUTOMATICALLY GENERATED. DO NOT EDIT. |
5 | */ | | 5 | */ |
6 | | | 6 | |
7 | #ifndef _RUMP_RUMPDEFS_H_ | | 7 | #ifndef _RUMP_RUMPDEFS_H_ |
8 | #define _RUMP_RUMPDEFS_H_ | | 8 | #define _RUMP_RUMPDEFS_H_ |
9 | | | 9 | |
10 | #include <rump/rump_namei.h> | | 10 | #include <rump/rump_namei.h> |
11 | | | 11 | |
12 | /* NetBSD: fcntl.h,v 1.46 2013/09/15 10:41:20 njoly Exp */ | | 12 | /* NetBSD: fcntl.h,v 1.46 2013/09/15 10:41:20 njoly Exp */ |
13 | #define RUMP_O_RDONLY 0x00000000 /* open for reading only */ | | 13 | #define RUMP_O_RDONLY 0x00000000 /* open for reading only */ |
14 | #define RUMP_O_WRONLY 0x00000001 /* open for writing only */ | | 14 | #define RUMP_O_WRONLY 0x00000001 /* open for writing only */ |
| @@ -230,27 +230,28 @@ enum rump_vtype { RUMP_VNON, RUMP_VREG, | | | @@ -230,27 +230,28 @@ enum rump_vtype { RUMP_VNON, RUMP_VREG, |
230 | #define RUMP_AF_LINK 18 | | 230 | #define RUMP_AF_LINK 18 |
231 | #define RUMP_AF_COIP 20 | | 231 | #define RUMP_AF_COIP 20 |
232 | #define RUMP_AF_CNT 21 | | 232 | #define RUMP_AF_CNT 21 |
233 | #define RUMP_AF_IPX 23 | | 233 | #define RUMP_AF_IPX 23 |
234 | #define RUMP_AF_INET6 24 | | 234 | #define RUMP_AF_INET6 24 |
235 | #define RUMP_AF_ISDN 26 | | 235 | #define RUMP_AF_ISDN 26 |
236 | #define RUMP_AF_E164 RUMP_AF_ISDN | | 236 | #define RUMP_AF_E164 RUMP_AF_ISDN |
237 | #define RUMP_AF_NATM 27 | | 237 | #define RUMP_AF_NATM 27 |
238 | #define RUMP_AF_ARP 28 | | 238 | #define RUMP_AF_ARP 28 |
239 | #define RUMP_AF_BLUETOOTH 31 | | 239 | #define RUMP_AF_BLUETOOTH 31 |
240 | #define RUMP_AF_IEEE80211 32 | | 240 | #define RUMP_AF_IEEE80211 32 |
241 | #define RUMP_AF_MPLS 33 | | 241 | #define RUMP_AF_MPLS 33 |
242 | #define RUMP_AF_ROUTE 34 | | 242 | #define RUMP_AF_ROUTE 34 |
243 | #define RUMP_AF_MAX 35 | | 243 | #define RUMP_AF_CAN 35 |
| | | 244 | #define RUMP_AF_MAX 36 |
244 | #define RUMP_PF_UNSPEC RUMP_AF_UNSPEC | | 245 | #define RUMP_PF_UNSPEC RUMP_AF_UNSPEC |
245 | #define RUMP_PF_LOCAL RUMP_AF_LOCAL | | 246 | #define RUMP_PF_LOCAL RUMP_AF_LOCAL |
246 | #define RUMP_PF_UNIX RUMP_PF_LOCAL | | 247 | #define RUMP_PF_UNIX RUMP_PF_LOCAL |
247 | #define RUMP_PF_INET RUMP_AF_INET | | 248 | #define RUMP_PF_INET RUMP_AF_INET |
248 | #define RUMP_PF_IMPLINK RUMP_AF_IMPLINK | | 249 | #define RUMP_PF_IMPLINK RUMP_AF_IMPLINK |
249 | #define RUMP_PF_PUP RUMP_AF_PUP | | 250 | #define RUMP_PF_PUP RUMP_AF_PUP |
250 | #define RUMP_PF_CHAOS RUMP_AF_CHAOS | | 251 | #define RUMP_PF_CHAOS RUMP_AF_CHAOS |
251 | #define RUMP_PF_NS RUMP_AF_NS | | 252 | #define RUMP_PF_NS RUMP_AF_NS |
252 | #define RUMP_PF_ISO RUMP_AF_ISO | | 253 | #define RUMP_PF_ISO RUMP_AF_ISO |
253 | #define RUMP_PF_OSI RUMP_AF_ISO | | 254 | #define RUMP_PF_OSI RUMP_AF_ISO |
254 | #define RUMP_PF_ECMA RUMP_AF_ECMA | | 255 | #define RUMP_PF_ECMA RUMP_AF_ECMA |
255 | #define RUMP_PF_DATAKIT RUMP_AF_DATAKIT | | 256 | #define RUMP_PF_DATAKIT RUMP_AF_DATAKIT |
256 | #define RUMP_PF_CCITT RUMP_AF_CCITT | | 257 | #define RUMP_PF_CCITT RUMP_AF_CCITT |
| @@ -267,26 +268,27 @@ enum rump_vtype { RUMP_VNON, RUMP_VREG, | | | @@ -267,26 +268,27 @@ enum rump_vtype { RUMP_VNON, RUMP_VREG, |
267 | #define RUMP_PF_CNT RUMP_AF_CNT | | 268 | #define RUMP_PF_CNT RUMP_AF_CNT |
268 | #define RUMP_PF_INET6 RUMP_AF_INET6 | | 269 | #define RUMP_PF_INET6 RUMP_AF_INET6 |
269 | #define RUMP_PF_IPX RUMP_AF_IPX | | 270 | #define RUMP_PF_IPX RUMP_AF_IPX |
270 | #define RUMP_PF_RTIP pseudo_RUMP_AF_RTIP | | 271 | #define RUMP_PF_RTIP pseudo_RUMP_AF_RTIP |
271 | #define RUMP_PF_PIP pseudo_RUMP_AF_PIP | | 272 | #define RUMP_PF_PIP pseudo_RUMP_AF_PIP |
272 | #define RUMP_PF_ISDN RUMP_AF_ISDN | | 273 | #define RUMP_PF_ISDN RUMP_AF_ISDN |
273 | #define RUMP_PF_E164 RUMP_AF_E164 | | 274 | #define RUMP_PF_E164 RUMP_AF_E164 |
274 | #define RUMP_PF_NATM RUMP_AF_NATM | | 275 | #define RUMP_PF_NATM RUMP_AF_NATM |
275 | #define RUMP_PF_ARP RUMP_AF_ARP | | 276 | #define RUMP_PF_ARP RUMP_AF_ARP |
276 | #define RUMP_PF_KEY pseudo_RUMP_AF_KEY | | 277 | #define RUMP_PF_KEY pseudo_RUMP_AF_KEY |
277 | #define RUMP_PF_BLUETOOTH RUMP_AF_BLUETOOTH | | 278 | #define RUMP_PF_BLUETOOTH RUMP_AF_BLUETOOTH |
278 | #define RUMP_PF_MPLS RUMP_AF_MPLS | | 279 | #define RUMP_PF_MPLS RUMP_AF_MPLS |
279 | #define RUMP_PF_ROUTE RUMP_AF_ROUTE | | 280 | #define RUMP_PF_ROUTE RUMP_AF_ROUTE |
| | | 281 | #define RUMP_PF_CAN RUMP_AF_CAN |
280 | #define RUMP_PF_MAX RUMP_AF_MAX | | 282 | #define RUMP_PF_MAX RUMP_AF_MAX |
281 | #define RUMP_SO_DEBUG 0x0001 | | 283 | #define RUMP_SO_DEBUG 0x0001 |
282 | #define RUMP_SO_ACCEPTCONN 0x0002 | | 284 | #define RUMP_SO_ACCEPTCONN 0x0002 |
283 | #define RUMP_SO_REUSEADDR 0x0004 | | 285 | #define RUMP_SO_REUSEADDR 0x0004 |
284 | #define RUMP_SO_KEEPALIVE 0x0008 | | 286 | #define RUMP_SO_KEEPALIVE 0x0008 |
285 | #define RUMP_SO_DONTROUTE 0x0010 | | 287 | #define RUMP_SO_DONTROUTE 0x0010 |
286 | #define RUMP_SO_BROADCAST 0x0020 | | 288 | #define RUMP_SO_BROADCAST 0x0020 |
287 | #define RUMP_SO_USELOOPBACK 0x0040 | | 289 | #define RUMP_SO_USELOOPBACK 0x0040 |
288 | #define RUMP_SO_LINGER 0x0080 | | 290 | #define RUMP_SO_LINGER 0x0080 |
289 | #define RUMP_SO_OOBINLINE 0x0100 | | 291 | #define RUMP_SO_OOBINLINE 0x0100 |
290 | #define RUMP_SO_REUSEPORT 0x0200 | | 292 | #define RUMP_SO_REUSEPORT 0x0200 |
291 | #define RUMP_SO_NOSIGPIPE 0x0800 | | 293 | #define RUMP_SO_NOSIGPIPE 0x0800 |
292 | #define RUMP_SO_ACCEPTFILTER 0x1000 | | 294 | #define RUMP_SO_ACCEPTFILTER 0x1000 |
--- src/sys/rump/net/Makefile.rumpnetcomp 2016/11/26 03:17:58 1.16
+++ src/sys/rump/net/Makefile.rumpnetcomp 2017/01/15 20:27:34 1.16.2.1
| @@ -1,19 +1,19 @@ | | | @@ -1,19 +1,19 @@ |
1 | # $NetBSD: Makefile.rumpnetcomp,v 1.16 2016/11/26 03:17:58 ozaki-r Exp $ | | 1 | # $NetBSD: Makefile.rumpnetcomp,v 1.16.2.1 2017/01/15 20:27:34 bouyer Exp $ |
2 | # | | 2 | # |
3 | | | 3 | |
4 | .include <bsd.own.mk> | | 4 | .include <bsd.own.mk> |
5 | | | 5 | |
6 | RUMPNETCOMP= agr bridge net net80211 netbt netinet netinet6 | | 6 | RUMPNETCOMP= agr bridge net net80211 netbt netcan netinet netinet6 |
7 | RUMPNETCOMP+= gif netmpls npf local pppoe shmif tap tun vlan | | 7 | RUMPNETCOMP+= gif netmpls npf local pppoe shmif tap tun vlan |
8 | | | 8 | |
9 | .if ${MKSLJIT} != "no" || make(rumpdescribe) | | 9 | .if ${MKSLJIT} != "no" || make(rumpdescribe) |
10 | RUMPNETCOMP+= bpfjit | | 10 | RUMPNETCOMP+= bpfjit |
11 | .endif | | 11 | .endif |
12 | | | 12 | |
13 | .if ${RUMP_VIRTIF:Uyes} == "yes" || make(rumpdescribe) | | 13 | .if ${RUMP_VIRTIF:Uyes} == "yes" || make(rumpdescribe) |
14 | RUMPNETCOMP+= virtif | | 14 | RUMPNETCOMP+= virtif |
15 | .endif | | 15 | .endif |
16 | | | 16 | |
17 | RUMPNETSOCKIN= sockin | | 17 | RUMPNETSOCKIN= sockin |
18 | | | 18 | |
19 | .for var in ${RUMPNETCOMP} | | 19 | .for var in ${RUMPNETCOMP} |
# $NetBSD: Makefile,v 1.1.2.1 2017/01/15 20:27:34 bouyer Exp $
#
NOLINT= #defined
.include <bsd.own.mk>
.PATH: ${.CURDIR}/../../../../netcan
LIB= rumpnet_netcan
COMMENT=CAN (PF_CAN)
IOCONF= NETCAN.ioconf
SRCS= can.c can_pcb.c can_proto.c if_canloop.c
SRCS+= netcan_component.c
.include <bsd.lib.mk>
.include <bsd.klinks.mk>
# $NetBSD: NETCAN.ioconf,v 1.1.2.1 2017/01/15 20:27:34 bouyer Exp $
ioconf netcan
include "conf/files"
pseudo-device canloop
/* $NetBSD: netcan_component.c,v 1.1.2.1 2017/01/15 20:27:34 bouyer Exp $ */
/*
* Copyright (c) 2010 Antti Kantee. 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 AUTHOR ``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 AUTHOR 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.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: netcan_component.c,v 1.1.2.1 2017/01/15 20:27:34 bouyer Exp $");
#include <sys/param.h>
#include <sys/domain.h>
#include <sys/protosw.h>
#include <rump-sys/kern.h>
#include <rump-sys/net.h>
#include <net/netisr.h>
#include <netcan/can_var.h>
RUMP_COMPONENT(RUMP_COMPONENT_NET)
{
extern struct domain candomain;
domain_attach(&candomain);
rump_netisr_register(NETISR_CAN, canintr);
}
void canloopinit(void);
RUMP_COMPONENT(RUMP_COMPONENT_NET_IF)
{
canloopinit();
}
--- src/sys/sys/socket.h 2016/09/21 10:50:23 1.120
+++ src/sys/sys/socket.h 2017/01/15 20:27:34 1.120.2.1
| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: socket.h,v 1.120 2016/09/21 10:50:23 roy Exp $ */ | | 1 | /* $NetBSD: socket.h,v 1.120.2.1 2017/01/15 20:27:34 bouyer Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | | 4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. |
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. |
| @@ -211,27 +211,28 @@ struct accept_filter_arg { | | | @@ -211,27 +211,28 @@ struct accept_filter_arg { |
211 | #define AF_ISDN 26 /* Integrated Services Digital Network*/ | | 211 | #define AF_ISDN 26 /* Integrated Services Digital Network*/ |
212 | #define AF_E164 AF_ISDN /* CCITT E.164 recommendation */ | | 212 | #define AF_E164 AF_ISDN /* CCITT E.164 recommendation */ |
213 | #define AF_NATM 27 /* native ATM access */ | | 213 | #define AF_NATM 27 /* native ATM access */ |
214 | #define AF_ARP 28 /* (rev.) addr. res. prot. (RFC 826) */ | | 214 | #define AF_ARP 28 /* (rev.) addr. res. prot. (RFC 826) */ |
215 | #if defined(_NETBSD_SOURCE) | | 215 | #if defined(_NETBSD_SOURCE) |
216 | #define pseudo_AF_KEY 29 /* Internal key management protocol */ | | 216 | #define pseudo_AF_KEY 29 /* Internal key management protocol */ |
217 | #define pseudo_AF_HDRCMPLT 30 /* Used by BPF to not rewrite hdrs | | 217 | #define pseudo_AF_HDRCMPLT 30 /* Used by BPF to not rewrite hdrs |
218 | in interface output routine */ | | 218 | in interface output routine */ |
219 | #endif | | 219 | #endif |
220 | #define AF_BLUETOOTH 31 /* Bluetooth: HCI, SCO, L2CAP, RFCOMM */ | | 220 | #define AF_BLUETOOTH 31 /* Bluetooth: HCI, SCO, L2CAP, RFCOMM */ |
221 | #define AF_IEEE80211 32 /* IEEE80211 */ | | 221 | #define AF_IEEE80211 32 /* IEEE80211 */ |
222 | #define AF_MPLS 33 /* MultiProtocol Label Switching */ | | 222 | #define AF_MPLS 33 /* MultiProtocol Label Switching */ |
223 | #define AF_ROUTE 34 /* Internal Routing Protocol */ | | 223 | #define AF_ROUTE 34 /* Internal Routing Protocol */ |
224 | #define AF_MAX 35 | | 224 | #define AF_CAN 35 |
| | | 225 | #define AF_MAX 36 |
225 | | | 226 | |
226 | /* | | 227 | /* |
227 | * Structure used by kernel to store most | | 228 | * Structure used by kernel to store most |
228 | * addresses. | | 229 | * addresses. |
229 | */ | | 230 | */ |
230 | struct sockaddr { | | 231 | struct sockaddr { |
231 | __uint8_t sa_len; /* total length */ | | 232 | __uint8_t sa_len; /* total length */ |
232 | sa_family_t sa_family; /* address family */ | | 233 | sa_family_t sa_family; /* address family */ |
233 | char sa_data[14]; /* actually longer; address value */ | | 234 | char sa_data[14]; /* actually longer; address value */ |
234 | }; | | 235 | }; |
235 | | | 236 | |
236 | #if defined(_KERNEL) | | 237 | #if defined(_KERNEL) |
237 | /* | | 238 | /* |
| @@ -320,26 +321,27 @@ struct sockaddr_storage { | | | @@ -320,26 +321,27 @@ struct sockaddr_storage { |
320 | #define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */ | | 321 | #define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */ |
321 | #define PF_PIP pseudo_AF_PIP | | 322 | #define PF_PIP pseudo_AF_PIP |
322 | #endif | | 323 | #endif |
323 | #define PF_ISDN AF_ISDN /* same as E164 */ | | 324 | #define PF_ISDN AF_ISDN /* same as E164 */ |
324 | #define PF_E164 AF_E164 | | 325 | #define PF_E164 AF_E164 |
325 | #define PF_NATM AF_NATM | | 326 | #define PF_NATM AF_NATM |
326 | #define PF_ARP AF_ARP | | 327 | #define PF_ARP AF_ARP |
327 | #if defined(_NETBSD_SOURCE) | | 328 | #if defined(_NETBSD_SOURCE) |
328 | #define PF_KEY pseudo_AF_KEY /* like PF_ROUTE, only for key mgmt */ | | 329 | #define PF_KEY pseudo_AF_KEY /* like PF_ROUTE, only for key mgmt */ |
329 | #endif | | 330 | #endif |
330 | #define PF_BLUETOOTH AF_BLUETOOTH | | 331 | #define PF_BLUETOOTH AF_BLUETOOTH |
331 | #define PF_MPLS AF_MPLS | | 332 | #define PF_MPLS AF_MPLS |
332 | #define PF_ROUTE AF_ROUTE | | 333 | #define PF_ROUTE AF_ROUTE |
| | | 334 | #define PF_CAN AF_CAN |
333 | | | 335 | |
334 | #define PF_MAX AF_MAX | | 336 | #define PF_MAX AF_MAX |
335 | | | 337 | |
336 | #if defined(_NETBSD_SOURCE) | | 338 | #if defined(_NETBSD_SOURCE) |
337 | | | 339 | |
338 | #ifndef pid_t | | 340 | #ifndef pid_t |
339 | typedef __pid_t pid_t; /* process id */ | | 341 | typedef __pid_t pid_t; /* process id */ |
340 | #define pid_t __pid_t | | 342 | #define pid_t __pid_t |
341 | #endif | | 343 | #endif |
342 | | | 344 | |
343 | #ifndef gid_t | | 345 | #ifndef gid_t |
344 | typedef __gid_t gid_t; /* group id */ | | 346 | typedef __gid_t gid_t; /* group id */ |
345 | #define gid_t __gid_t | | 347 | #define gid_t __gid_t |