Source-Changes-HG archive

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

[src/trunk]: src/sys/net Add interface media for sppp consumers.



details:   https://anonhg.NetBSD.org/src/rev/ed31d76d1f7c
branches:  trunk
changeset: 347739:ed31d76d1f7c
user:      roy <roy%NetBSD.org@localhost>
date:      Wed Sep 14 10:58:38 2016 +0000

description:
Add interface media for sppp consumers.
While there is no actual media to select,
the ioctl is used to query link status from userland.

diffstat:

 sys/net/if_spppsubr.c |  38 ++++++++++++++++++++++++++++++++++++--
 sys/net/if_spppvar.h  |   5 ++++-
 2 files changed, 40 insertions(+), 3 deletions(-)

diffs (99 lines):

diff -r 2f24b2f33b3f -r ed31d76d1f7c sys/net/if_spppsubr.c
--- a/sys/net/if_spppsubr.c     Wed Sep 14 03:19:11 2016 +0000
+++ b/sys/net/if_spppsubr.c     Wed Sep 14 10:58:38 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_spppsubr.c,v 1.149 2016/09/13 19:51:12 joerg Exp $   */
+/*     $NetBSD: if_spppsubr.c,v 1.150 2016/09/14 10:58:38 roy Exp $     */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.149 2016/09/13 19:51:12 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.150 2016/09/14 10:58:38 roy Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -861,6 +861,31 @@
        return error;
 }
 
+static int
+sppp_mediachange(struct ifnet *ifp)
+{
+
+       return (0);
+}
+
+static void
+sppp_mediastatus(struct ifnet *ifp, struct ifmediareq *imr)
+{
+
+       switch (ifp->if_link_state) {
+       case LINK_STATE_UP:
+               imr->ifm_status = IFM_AVALID | IFM_ACTIVE;
+               break;
+       case LINK_STATE_DOWN:
+               imr->ifm_status = IFM_AVALID;
+               break;
+       default:
+               /* Should be impossible as we set link state down in attach. */
+               imr->ifm_status = 0;
+               break;
+       }
+}
+
 void
 sppp_attach(struct ifnet *ifp)
 {
@@ -897,6 +922,11 @@
 
        if_alloc_sadl(ifp);
 
+       /* Lets not beat about the bush, we know we're down. */
+       ifp->if_link_state = LINK_STATE_DOWN;
+       /* There is no media for PPP, but it's needed to report link status. */
+       ifmedia_init(&sp->pp_im, 0, sppp_mediachange, sppp_mediastatus);
+
        memset(&sp->myauth, 0, sizeof sp->myauth);
        memset(&sp->hisauth, 0, sizeof sp->hisauth);
        sppp_lcp_init(sp);
@@ -1101,6 +1131,10 @@
                error = sppp_params(sp, cmd, data);
                break;
 
+       case SIOCGIFMEDIA:
+               error = ifmedia_ioctl(ifp, ifr, &sp->pp_im, cmd);
+               break;
+
        default:
                error = ifioctl_common(ifp, cmd, data);
                break;
diff -r 2f24b2f33b3f -r ed31d76d1f7c sys/net/if_spppvar.h
--- a/sys/net/if_spppvar.h      Wed Sep 14 03:19:11 2016 +0000
+++ b/sys/net/if_spppvar.h      Wed Sep 14 10:58:38 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_spppvar.h,v 1.16 2009/10/05 21:27:36 dyoung Exp $   */
+/*     $NetBSD: if_spppvar.h,v 1.17 2016/09/14 10:58:38 roy Exp $      */
 
 #ifndef _NET_IF_SPPPVAR_H_
 #define _NET_IF_SPPPVAR_H_
@@ -26,6 +26,8 @@
  * From: Id: if_sppp.h,v 1.7 1998/12/01 20:20:19 hm Exp
  */
 
+#include <net/if_media.h>
+
 #define IDX_LCP 0              /* idx into state table */
 
 struct slcp {
@@ -79,6 +81,7 @@
 struct sppp {
        /* NB: pp_if _must_ be first */
        struct  ifnet pp_if;    /* network interface data */
+       struct  ifmedia pp_im;  /* interface media, to report link status */
        struct  ifqueue pp_fastq; /* fast output queue */
        struct  ifqueue pp_cpq; /* PPP control protocol queue */
        struct  sppp *pp_next;  /* next interface in keepalive list */



Home | Main Index | Thread Index | Old Index