Date: Mon, 22 Aug 2016 20:16:59 GMT From: yuanxunzhang@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r308210 - in soc2016/yuanxunzhang/head: sys/net usr.sbin/eaps Message-ID: <201608222016.u7MKGxQj040602@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: yuanxunzhang Date: Mon Aug 22 20:16:58 2016 New Revision: 308210 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=308210 Log: EAPS: implement add primary/secondary port interface Modified: soc2016/yuanxunzhang/head/sys/net/eaps.c soc2016/yuanxunzhang/head/sys/net/eaps.h soc2016/yuanxunzhang/head/usr.sbin/eaps/eaps.c soc2016/yuanxunzhang/head/usr.sbin/eaps/eaps.h Modified: soc2016/yuanxunzhang/head/sys/net/eaps.c ============================================================================== --- soc2016/yuanxunzhang/head/sys/net/eaps.c Mon Aug 22 19:58:42 2016 (r308209) +++ soc2016/yuanxunzhang/head/sys/net/eaps.c Mon Aug 22 20:16:58 2016 (r308210) @@ -72,11 +72,13 @@ static void eaps_init(void *); void eaps_attach(struct eaps_softc *); void eaps_detach(struct eaps_softc *); -void eaps_status(struct eaps_softc *, struct eaps_state *); -void set_eaps_mode(struct eaps_softc *, struct eaps_state *); -void set_eaps_priority(struct eaps_softc *, struct eaps_state *); -void set_eaps_hellotime(struct eaps_softc *, struct eaps_state *); -void set_eaps_failtime(struct eaps_softc *, struct eaps_state *); +int eaps_status(struct eaps_softc *, struct eaps_state *); +int set_eaps_mode(struct eaps_softc *, struct eaps_state *); +int set_eaps_priority(struct eaps_softc *, struct eaps_state *); +int set_eaps_hellotime(struct eaps_softc *, struct eaps_state *); +int set_eaps_failtime(struct eaps_softc *, struct eaps_state *); +int set_eaps_primary_port(struct eaps_softc *, struct eaps_state *); +int set_eaps_secondary_port(struct eaps_softc *, struct eaps_state *); static VNET_DEFINE(struct if_clone *, eaps_cloner); #define V_eaps_cloner VNET(eaps_cloner) @@ -209,23 +211,23 @@ switch (cmd) { case SIOCSEAPSDOMAIN: - eaps_status(sc, es); + error = eaps_status(sc, es); break; case SIOCSEAPSMODE: - set_eaps_mode(sc, es); + error = set_eaps_mode(sc, es); break; case SIOCSEAPSPRI: - set_eaps_priority(sc, es); + error = set_eaps_priority(sc, es); break; case SIOCSEAPSHELLO: - set_eaps_hellotime(sc, es); + error = set_eaps_hellotime(sc, es); break; case SIOCSEAPSFAIL: - set_eaps_failtime(sc, es); + error = set_eaps_failtime(sc, es); break; default: error = ether_ioctl(ifp, cmd, data); @@ -258,7 +260,7 @@ } -void +int eaps_status(struct eaps_softc *sc, struct eaps_state *es) { printf("Debug print: Query eaps domain status!\n"); @@ -272,42 +274,81 @@ es->failtime = sc->sc_eaps.failtime; (void) strlcpy(es->ifname, sc->sc_ifp->if_xname, sizeof(sc->sc_ifp->if_xname)); EAPS_RUNLOCK(sc, &tracker); + + reutrn (0); } -void +int set_eaps_mode(struct eaps_softc *sc, struct eaps_state *es) { printf("Debug print: set_eaps_mode!\n"); EAPS_WLOCK(sc); sc->sc_eaps.mode = es->mode; EAPS_WUNLOCK(sc); + reutrn (0); } -void +int set_eaps_priority(struct eaps_softc *sc, struct eaps_state *es) { printf("Debug print: set_eaps_priority!\n"); EAPS_WLOCK(sc); sc->sc_eaps.priority = es->priority; EAPS_WUNLOCK(sc); + reutrn (0); } -void +int set_eaps_hellotime(struct eaps_softc *sc, struct eaps_state *es) { EAPS_WLOCK(sc); sc->sc_eaps.hellotime = es->hellotime; EAPS_WUNLOCK(sc); + + reutrn (0); } -void +int set_eaps_failtime(struct eaps_softc *sc, struct eaps_state *es) { EAPS_WLOCK(sc); sc->sc_eaps.failtime = es->failtime; EAPS_WUNLOCK(sc); + + reutrn (0); } +int +set_eaps_primary_port(struct eaps_softc *sc, struct eaps_state *es) +{ + int error = 0; + + char p_port[IFNAMSIZ] = NULL; + (void) strlcpy(p_port, es->p_port, sizeof(es->p_port)); + + struct rm_priotracker tracker; + EAPS_RLOCK(sc, &tracker); + + // If the primary port has already used for secondary port, return error + if (sc->sc_eaps.s_port == p_port) { + return ENODEV; + } + EAPS_RUNLOCK(sc, &tracker); + + EAPS_WLOCK(sc); + sc->sc_eaps.p_port = p_port + EAPS_WUNLOCK(sc); + + reutrn (0); +} + +int +set_eaps_secondary_port(struct eaps_softc *sc, struct eaps_state *es) +{ + reutrn (0); +} + + void eaps_attach(struct eaps_softc *sc) { @@ -319,6 +360,8 @@ sc->sc_eaps.priority = EAPS_PRIORITY_NORMAL; sc->sc_eaps.hellotime = EAPS_HELLO_TIME_DEFAULT; sc->sc_eaps.failtime = EAPS_FAIL_TIME_DEFAULT; + sc->sc_eaps.p_port = NULL; + sc->sc_eaps.s_port = NULL; EAPS_WUNLOCK(sc); } Modified: soc2016/yuanxunzhang/head/sys/net/eaps.h ============================================================================== --- soc2016/yuanxunzhang/head/sys/net/eaps.h Mon Aug 22 19:58:42 2016 (r308209) +++ soc2016/yuanxunzhang/head/sys/net/eaps.h Mon Aug 22 20:16:58 2016 (r308210) @@ -36,13 +36,15 @@ * eaps state information */ struct eaps_state { - char ifname[IFNAMSIZ]; /* name of the eaps */ - uint8_t state; /* state of eaps */ - uint8_t status; /* enable or disable eaps */ - uint8_t mode; /* switch mode for a node: transit or master, default transit */ - uint8_t priority; /* EAPS domain priority high or normal */ - int32_t hellotime; /* hello time is set by master node for sending health check message */ - int32_t failtime; /* fail time is set by master node for waiting before the failtimer expires */ + char ifname[IFNAMSIZ]; /* name of the eaps */ + uint8_t state; /* state of eaps */ + uint8_t status; /* enable or disable eaps */ + uint8_t mode; /* switch mode for a node: transit or master, default transit */ + uint8_t priority; /* EAPS domain priority high or normal */ + int32_t hellotime; /* hello time is set by master node for sending health check message */ + int32_t failtime; /* fail time is set by master node for waiting before the failtimer expires */ + char p_port[IFNAMSIZ]; /* primary port of this eaps node, which is valid when it's master node */ + char s_port[IFNAMSIZ]; /* secondary port of this eaps node, which is valid for master and transit */ }; /* @@ -61,7 +63,8 @@ #define SIOCSEAPSPRI _IOW('i', 302, struct eaps_state) #define SIOCSEAPSHELLO _IOW('i', 303, struct eaps_state) #define SIOCSEAPSFAIL _IOW('i', 304, struct eaps_state) - +#define SIOCESAPSPRIMARY _IOW('i', 305, struct eaps_state) +#define SIOCESAPSSECONDARY _IOW('i', 306, struct eaps_state) /* * Extreme Active Protection System (EAPS) definitions. * Normative reference: draft-shah-extreme-rfc3619bis-02 [Expired I-D] Modified: soc2016/yuanxunzhang/head/usr.sbin/eaps/eaps.c ============================================================================== --- soc2016/yuanxunzhang/head/usr.sbin/eaps/eaps.c Mon Aug 22 19:58:42 2016 (r308209) +++ soc2016/yuanxunzhang/head/usr.sbin/eaps/eaps.c Mon Aug 22 20:16:58 2016 (r308210) @@ -241,6 +241,21 @@ printf("\tpriority: %s\n", eaps_priority_message[es.priority]); printf("\thellotime: %d (milliseconds)\n", es.hellotime); printf("\tfailtime: %d (milliseconds)\n", es.failtime); + + if (es.p_port == NULL) + { + printf("\tprimary port: not assigned\n"); + } else { + printf("\tprimary port: %s\n", es.p_port); + } + + if (es.s_port == NULL) + { + printf("\tsecondary port: not assigned\n"); + } else { + printf("\tsecondary port: %s\n", es.s_port); + } + } else { printf("Debug print: ioctl failed!\n"); err(1, "SIOCSEAPSDOMAIN"); @@ -264,6 +279,12 @@ 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); + } + char *mode = *(++argv); printf("Debug print: set switch mode is %s!\n", mode); @@ -338,6 +359,12 @@ 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); + } + int32_t hellotime = atoi(*(++argv)); printf("Debug print: set_eaps_hellotime %d!\n", hellotime); @@ -376,6 +403,12 @@ 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); + } + int32_t failtime = atoi(*(++argv)); printf("Debug print: set_eaps_failtime %d!\n", failtime); @@ -402,15 +435,39 @@ static void set_eaps_primary_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); + } + + es.p_port = port_name; + if (ioctl(s, SIOCESAPSPRIMARY, &es) != 0) + err(1, "SIOCESAPSPRIMARY"); + + exit(error); } static void Modified: soc2016/yuanxunzhang/head/usr.sbin/eaps/eaps.h ============================================================================== --- soc2016/yuanxunzhang/head/usr.sbin/eaps/eaps.h Mon Aug 22 19:58:42 2016 (r308209) +++ soc2016/yuanxunzhang/head/usr.sbin/eaps/eaps.h Mon Aug 22 20:16:58 2016 (r308210) @@ -42,13 +42,15 @@ * eaps state information */ struct eaps_state { - char ifname[IFNAMSIZ]; /* name of the eaps */ - uint8_t state; /* state of eaps */ - uint8_t status; /* enable or disable eaps */ - uint8_t mode; /* switch mode for a node: transit or master, default transit */ - uint8_t priority; /* EAPS domain priority high or normal */ - int32_t hellotime; /* hello time is set by master node for sending health check message */ - int32_t failtime; /* fail time is set by master node for waiting before the failtimer expires */ + char ifname[IFNAMSIZ]; /* name of the eaps */ + uint8_t state; /* state of eaps */ + uint8_t status; /* enable or disable eaps */ + uint8_t mode; /* switch mode for a node: transit or master, default transit */ + uint8_t priority; /* EAPS domain priority high or normal */ + int32_t hellotime; /* hello time is set by master node for sending health check message */ + int32_t failtime; /* fail time is set by master node for waiting before the failtimer expires */ + char p_port[IFNAMSIZ]; /* primary port of this eaps node, which is valid when it's master node */ + char s_port[IFNAMSIZ]; /* secondary port of this eaps node, which is valid for master and transit */ }; /* @@ -63,9 +65,11 @@ #define EAPS_PRIORITY_NORMAL 0x00 /* EAPS domain priority - normal */ #define EAPS_PRIORITY_HIGH 0x01 /* EAPS domain priority - high (default) */ -#define SIOCSEAPSDOMAIN _IOWR('i', 300, struct eaps_state) -#define SIOCSEAPSMODE _IOW('i', 301, struct eaps_state) -#define SIOCSEAPSPRI _IOW('i', 302, struct eaps_state) -#define SIOCSEAPSHELLO _IOW('i', 303, struct eaps_state) -#define SIOCSEAPSFAIL _IOW('i', 304, struct eaps_state) +#define SIOCSEAPSDOMAIN _IOWR('i', 300, struct eaps_state) +#define SIOCSEAPSMODE _IOW('i', 301, struct eaps_state) +#define SIOCSEAPSPRI _IOW('i', 302, struct eaps_state) +#define SIOCSEAPSHELLO _IOW('i', 303, struct eaps_state) +#define SIOCSEAPSFAIL _IOW('i', 304, struct eaps_state) +#define SIOCESAPSPRIMARY _IOW('i', 305, struct eaps_state) +#define SIOCESAPSSECONDARY _IOW('i', 306, struct eaps_state)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201608222016.u7MKGxQj040602>