1 /* $NetBSD: can_pcb.h,v 1.2 2017/05/27 21:02:56 bouyer Exp $ */ 2 3 /*- 4 * Copyright (c) 2003, 2017 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Robert Swindells and Manuel Bouyer 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef _NETCAN_CAN_PCB_H_ 33 #define _NETCAN_CAN_PCB_H_ 34 35 #include <sys/queue.h> 36 37 /* 38 * Common structure pcb for can protocol implementation. 39 * Here are stored pointers to local and foreign host table 40 * entries, local and foreign socket numbers, and pointers 41 * up (to a socket structure) and down (to a protocol-specific) 42 * control block. 43 */ 44 struct canpcbpolicy; 45 46 47 struct canpcb { 48 LIST_ENTRY(canpcb) canp_hash; 49 LIST_ENTRY(canpcb) canp_lhash; 50 TAILQ_ENTRY(canpcb) canp_queue; 51 kmutex_t canp_mtx; /* protect states and refcount */ 52 int canp_state; 53 int canp_flags; 54 struct socket *canp_socket; /* back pointer to socket */ 55 struct ifnet *canp_ifp; /* interface this socket is bound to */ 56 57 struct canpcbtable *canp_table; 58 struct can_filter *canp_filters; /* filter array */ 59 int canp_nfilters; /* size of canp_filters */ 60 61 int canp_refcount; 62 }; 63 64 LIST_HEAD(canpcbhead, canpcb); 65 66 TAILQ_HEAD(canpcbqueue, canpcb); 67 68 struct canpcbtable { 69 struct canpcbqueue canpt_queue; 70 struct canpcbhead *canpt_bindhashtbl; 71 struct canpcbhead *canpt_connecthashtbl; 72 u_long canpt_bindhash; 73 u_long canpt_connecthash; 74 }; 75 76 /* states in canp_state: */ 77 #define CANP_DETACHED 0 78 #define CANP_ATTACHED 1 79 #define CANP_BOUND 2 80 #define CANP_CONNECTED 3 81 82 /* flags in canp_flags: */ 83 #define CANP_NO_LOOPBACK 0x0001 /* local loopback disabled */ 84 #define CANP_RECEIVE_OWN 0x0002 /* receive own message */ 85 86 87 #define sotocanpcb(so) ((struct canpcb *)(so)->so_pcb) 88 89 #ifdef _KERNEL 90 void can_losing(struct canpcb *); 91 int can_pcballoc (struct socket *, void *); 92 int can_pcbbind(void *, struct sockaddr_can *, struct lwp *); 93 int can_pcbconnect(void *, struct sockaddr_can *); 94 void can_pcbdetach(void *); 95 void can_pcbdisconnect(void *); 96 void can_pcbinit(struct canpcbtable *, int, int); 97 int can_pcbnotify(struct canpcbtable *, u_int32_t, 98 u_int32_t, int, void (*)(struct canpcb *, int)); 99 void can_pcbnotifyall(struct canpcbtable *, u_int32_t, int, 100 void (*)(struct canpcb *, int)); 101 void can_pcbpurgeif0(struct canpcbtable *, struct ifnet *); 102 void can_pcbpurgeif(struct canpcbtable *, struct ifnet *); 103 void can_pcbstate(struct canpcb *, int); 104 void can_setsockaddr(struct canpcb *, struct sockaddr_can *); 105 int can_pcbsetfilter(struct canpcb *, struct can_filter *, int); 106 bool can_pcbfilter(struct canpcb *, struct mbuf *); 107 108 /* refcount management */ 109 void canp_ref(struct canpcb *); 110 void canp_unref(struct canpcb *); 111 #endif 112 113 #endif /* _NETCAN_CAN_PCB_H_ */ 114