socsvn commit: r308259 - in soc2016/yuanxunzhang/head: sys/net usr.sbin/eaps
yuanxunzhang at FreeBSD.org
yuanxunzhang at FreeBSD.org
Tue Aug 23 10:01:37 UTC 2016
Author: yuanxunzhang
Date: Tue Aug 23 10:01:35 2016
New Revision: 308259
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=308259
Log:
EAPS: add primary/secondary port
Modified:
soc2016/yuanxunzhang/head/sys/net/eaps.c
soc2016/yuanxunzhang/head/usr.sbin/eaps/eaps.c
Modified: soc2016/yuanxunzhang/head/sys/net/eaps.c
==============================================================================
--- soc2016/yuanxunzhang/head/sys/net/eaps.c Tue Aug 23 08:13:08 2016 (r308258)
+++ soc2016/yuanxunzhang/head/sys/net/eaps.c Tue Aug 23 10:01:35 2016 (r308259)
@@ -282,6 +282,8 @@
es->hellotime = sc->sc_eaps.hellotime;
es->failtime = sc->sc_eaps.failtime;
(void) strlcpy(es->ifname, sc->sc_ifp->if_xname, sizeof(sc->sc_ifp->if_xname));
+ (void) strlcpy(es->p_port, sc->sc_eaps.p_port, sizeof(es->p_port));
+ (void) strlcpy(es->s_port, sc->sc_eaps.s_port, sizeof(es->s_port));
EAPS_RUNLOCK(sc, &tracker);
return (0);
@@ -304,7 +306,7 @@
EAPS_WLOCK(sc);
sc->sc_eaps.priority = es->priority;
EAPS_WUNLOCK(sc);
-
+
return (0);
}
@@ -336,12 +338,11 @@
struct rm_priotracker tracker;
EAPS_RLOCK(sc, &tracker);
-
- // If the primary port has already used for secondary port, return error
+ // If the port has already used for secondary port, then return error
if (strcmp(sc->sc_eaps.s_port, p_port) == 0) {
+ EAPS_RUNLOCK(sc, &tracker);
return ENODEV;
}
-
EAPS_RUNLOCK(sc, &tracker);
EAPS_WLOCK(sc);
@@ -354,6 +355,22 @@
int
set_eaps_secondary_port(struct eaps_softc *sc, struct eaps_state *es)
{
+ char s_port[IFNAMSIZ];
+ (void) strlcpy(s_port, es->s_port, sizeof(es->s_port));
+
+ struct rm_priotracker tracker;
+ EAPS_RLOCK(sc, &tracker);
+ // If the port has already used for primary port, then return error
+ if (strcmp(sc->sc_eaps.p_port, s_port) == 0) {
+ EAPS_RUNLOCK(sc, &tracker);
+ return ENODEV;
+ }
+ EAPS_RUNLOCK(sc, &tracker);
+
+ EAPS_WLOCK(sc);
+ (void) strlcpy(sc->sc_eaps.s_port, s_port, sizeof(sc->sc_eaps.s_port));
+ EAPS_WUNLOCK(sc);
+
return (0);
}
Modified: soc2016/yuanxunzhang/head/usr.sbin/eaps/eaps.c
==============================================================================
--- soc2016/yuanxunzhang/head/usr.sbin/eaps/eaps.c Tue Aug 23 08:13:08 2016 (r308258)
+++ soc2016/yuanxunzhang/head/usr.sbin/eaps/eaps.c Tue Aug 23 10:01:35 2016 (r308259)
@@ -474,7 +474,40 @@
static void
set_eaps_secondary_port(int argc, char **argv, int s)
{
+ int error = 0;
+ struct eaps_state es;
+ bzero(&es, sizeof(es));
+
+ // get eaps domain name
+ char *domain_name = *(++argv);
+
+ // check eaps domain name
+ if (domain_name == NULL) {
+ err(1, "EAPS domain name is NULL!");
+ }
+
+ // check if eaps domain exists
+ if (0 == if_nametoindex(domain_name))
+ {
+ errx(1, "EAPS domain %s does not exist", domain_name);
+ }
+
+ // get port name
+ char *port_name = *(++argv);
+
+ // check if eaps domain exists
+ if (0 == if_nametoindex(domain_name))
+ {
+ errx(1, "port %s does not exist", port_name);
+ }
+
+ strlcpy(es.ifname, domain_name, sizeof(es.ifname));
+ strlcpy(es.s_port, port_name, sizeof(es.s_port));
+ if (ioctl(s, SIOCESAPSSECONDARY, &es) != 0)
+ err(1, "SIOCESAPSSECONDARY");
+
+ exit(error);
}
static void
More information about the svn-soc-all
mailing list