Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/netcan Refuse to bind to a non-CAN interface.



details:   https://anonhg.NetBSD.org/src/rev/91b85340c886
branches:  trunk
changeset: 824577:91b85340c886
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Fri Jun 09 08:21:41 2017 +0000

description:
Refuse to bind to a non-CAN interface.
Also release the lock in the error branch.

diffstat:

 sys/netcan/can_pcb.c |  10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diffs (32 lines):

diff -r 715aff8a39b8 -r 91b85340c886 sys/netcan/can_pcb.c
--- a/sys/netcan/can_pcb.c      Fri Jun 09 07:32:24 2017 +0000
+++ b/sys/netcan/can_pcb.c      Fri Jun 09 08:21:41 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: can_pcb.c,v 1.5 2017/06/01 02:45:14 chs Exp $  */
+/*     $NetBSD: can_pcb.c,v 1.6 2017/06/09 08:21:41 bouyer Exp $       */
 
 /*-
  * Copyright (c) 2003, 2017 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: can_pcb.c,v 1.5 2017/06/01 02:45:14 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: can_pcb.c,v 1.6 2017/06/09 08:21:41 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -127,8 +127,12 @@
        mutex_enter(&canp->canp_mtx);
        if (scan->can_ifindex != 0) {
                canp->canp_ifp = if_byindex(scan->can_ifindex);
-               if (canp->canp_ifp == NULL)
+               if (canp->canp_ifp == NULL ||
+                   canp->canp_ifp->if_dlt != DLT_CAN_SOCKETCAN) {
+                       canp->canp_ifp = NULL;
+                       mutex_exit(&canp->canp_mtx);
                        return (EADDRNOTAVAIL);
+               }
                soisconnected(canp->canp_socket);
        } else {
                canp->canp_ifp = NULL;



Home | Main Index | Thread Index | Old Index