Lines Matching defs:canp
87 struct canpcb *canp;
98 canp = pool_get(&canpcb_pool, PR_NOWAIT);
100 if (canp == NULL) {
104 memset(canp, 0, sizeof(*canp));
105 canp->canp_table = table;
106 canp->canp_socket = so;
107 canp->canp_filters = can_init_filter;
108 canp->canp_nfilters = 1;
109 mutex_init(&canp->canp_mtx, MUTEX_DEFAULT, IPL_NET);
110 canp->canp_refcount = 1;
112 so->so_pcb = canp;
113 mutex_enter(&canp->canp_mtx);
114 TAILQ_INSERT_HEAD(&table->canpt_queue, canp, canp_queue);
115 can_pcbstate(canp, CANP_ATTACHED);
116 mutex_exit(&canp->canp_mtx);
123 struct canpcb *canp = v;
129 mutex_enter(&canp->canp_mtx);
131 canp->canp_ifp = if_byindex(scan->can_ifindex);
132 if (canp->canp_ifp == NULL ||
133 canp->canp_ifp->if_dlt != DLT_CAN_SOCKETCAN) {
134 canp->canp_ifp = NULL;
135 mutex_exit(&canp->canp_mtx);
138 soisconnected(canp->canp_socket);
140 canp->canp_ifp = NULL;
141 canp->canp_socket->so_state &= ~SS_ISCONNECTED; /* XXX */
143 can_pcbstate(canp, CANP_BOUND);
144 mutex_exit(&canp->canp_mtx);
155 struct canpcb *canp = v;
165 mutex_enter(&canp->canp_mtx);
166 memcpy(&canp->canp_dst, scan, sizeof(struct sockaddr_can));
167 can_pcbstate(canp, CANP_CONNECTED);
168 mutex_exit(&canp->canp_mtx);
177 struct canpcb *canp = v;
179 mutex_enter(&canp->canp_mtx);
180 can_pcbstate(canp, CANP_DETACHED);
181 mutex_exit(&canp->canp_mtx);
182 if (canp->canp_socket->so_state & SS_NOFDREF)
183 can_pcbdetach(canp);
189 struct canpcb *canp = v;
190 struct socket *so = canp->canp_socket;
194 mutex_enter(&canp->canp_mtx);
195 can_pcbstate(canp, CANP_DETACHED);
196 mutex_exit(&canp->canp_mtx);
197 can_pcbsetfilter(canp, NULL, 0);
198 TAILQ_REMOVE(&canp->canp_table->canpt_queue, canp, canp_queue);
200 canp_unref(canp);
205 canp_ref(struct canpcb *canp)
207 KASSERT(mutex_owned(&canp->canp_mtx));
208 canp->canp_refcount++;
212 canp_unref(struct canpcb *canp)
214 mutex_enter(&canp->canp_mtx);
215 canp->canp_refcount--;
216 KASSERT(canp->canp_refcount >= 0);
217 if (canp->canp_refcount > 0) {
218 mutex_exit(&canp->canp_mtx);
221 mutex_exit(&canp->canp_mtx);
222 mutex_destroy(&canp->canp_mtx);
223 pool_put(&canpcb_pool, canp);
227 can_setsockaddr(struct canpcb *canp, struct sockaddr_can *scan)
230 mutex_enter(&canp->canp_mtx);
234 if (canp->canp_ifp)
235 scan->can_ifindex = canp->canp_ifp->if_index;
238 mutex_exit(&canp->canp_mtx);
242 can_pcbsetfilter(struct canpcb *canp, struct can_filter *fp, int nfilters)
257 mutex_enter(&canp->canp_mtx);
258 oldf = canp->canp_filters;
259 oldnf = canp->canp_nfilters;
260 if (newf != NULL && canp->canp_state == CANP_DETACHED) {
263 canp->canp_filters = newf;
264 canp->canp_nfilters = nfilters;
267 mutex_exit(&canp->canp_mtx);
296 struct canpcb *canp, *ncanp;
304 for (canp = LIST_FIRST(head); canp != NULL; canp = ncanp) {
305 ncanp = LIST_NEXT(canp, canp_hash);
306 if (canp->canp_faddr == faddr &&
307 canp->canp_laddr == laddr) {
308 (*notify)(canp, errno);
319 struct canpcb *canp, *ncanp;
324 TAILQ_FOREACH_SAFE(canp, &table->canpt_queue, canp_queue, ncanp) {
325 if (canp->canp_faddr == faddr)
326 (*notify)(canp, errno);
335 struct canpcb *canp, *ncanp;
344 struct canpcb *canp, *ncanp;
346 for (canp = CIRCLEQ_FIRST(&table->canpt_queue);
347 canp != (void *)&table->canpt_queue;
348 canp = ncanp) {
349 ncanp = CIRCLEQ_NEXT(canp, canp_queue);
357 can_pcbstate(struct canpcb *canp, int state)
359 int ifindex = canp->canp_ifp ? canp->canp_ifp->if_index : 0;
360 KASSERT(mutex_owned(&canp->canp_mtx));
362 if (canp->canp_state > CANP_ATTACHED)
363 LIST_REMOVE(canp, canp_hash);
367 LIST_INSERT_HEAD(CANPCBHASH_BIND(canp->canp_table,
368 ifindex), canp, canp_hash);
371 LIST_INSERT_HEAD(CANPCBHASH_CONNECT(canp->canp_table,
372 ifindex), canp, canp_hash);
376 canp->canp_state = state;
384 can_pcbfilter(struct canpcb *canp, struct mbuf *m)
390 KASSERT(mutex_owned(&canp->canp_mtx));
395 for (i = 0; i < canp->canp_nfilters; i++) {
396 fip = &canp->canp_filters[i];