]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ip: Use specific slave id
authorHangbin Liu <liuhangbin@gmail.com>
Tue, 20 Sep 2016 10:02:12 +0000 (18:02 +0800)
committerStephen Hemminger <stephen@networkplumber.org>
Thu, 22 Sep 2016 23:39:55 +0000 (16:39 -0700)
The original bond/bridge/vrf and slaves use same id, which make people
confused. Use bond/bridge/vrf_slave as id name will make code more clear.

Acked-by: Phil Sutter <psutter@redhat.com>
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
ip/ip_common.h
ip/ipaddress.c
ip/iplink.c
ip/iplink_bond_slave.c
ip/iplink_bridge_slave.c
ip/iplink_vrf.c
ip/ipmacsec.c

index 93ff5bce4397831eadb94f198db4bed6de75eb8b..1c1cbdf0ab35f7eebb0dc1bdcc30d1401089d47c 100644 (file)
@@ -83,11 +83,9 @@ struct link_util {
                                             struct rtattr *);
        void                    (*print_help)(struct link_util *, int, char **,
                                             FILE *);
-       bool                    slave;
 };
 
 struct link_util *get_link_kind(const char *kind);
-struct link_util *get_link_slave_kind(const char *slave_kind);
 
 void br_dump_bridge_id(const struct ifla_bridge_id *id, char *buf, size_t len);
 
index 76bd7b35639f32508f0385c08a6e3f0d393b7b3d..fcc3c538d1bd88fbc66a46dbe885e607e06fb36c 100644 (file)
@@ -232,6 +232,7 @@ static void print_linktype(FILE *fp, struct rtattr *tb)
        struct rtattr *linkinfo[IFLA_INFO_MAX+1];
        struct link_util *lu;
        struct link_util *slave_lu;
+       char slave[32];
        char *kind;
        char *slave_kind;
 
@@ -265,8 +266,9 @@ static void print_linktype(FILE *fp, struct rtattr *tb)
 
                fprintf(fp, "%s", _SL_);
                fprintf(fp, "    %s_slave ", slave_kind);
+               snprintf(slave, sizeof(slave), "%s_slave", slave_kind);
 
-               slave_lu = get_link_slave_kind(slave_kind);
+               slave_lu = get_link_kind(slave);
                if (slave_lu && slave_lu->print_opt) {
                        struct rtattr *attr[slave_lu->maxattr+1], **data = NULL;
 
index 6b1db18a6135dc5d8dd9652eda8572216135d3bc..dec8268a0dbb4489a1b6775c660fa1fd60c2ce06 100644 (file)
@@ -119,15 +119,14 @@ static int on_off(const char *msg, const char *realval)
 static void *BODY;             /* cached dlopen(NULL) handle */
 static struct link_util *linkutil_list;
 
-static struct link_util *__get_link_kind(const char *id, bool slave)
+struct link_util *get_link_kind(const char *id)
 {
        void *dlh;
        char buf[256];
        struct link_util *l;
 
        for (l = linkutil_list; l; l = l->next)
-               if (strcmp(l->id, id) == 0 &&
-                   l->slave == slave)
+               if (strcmp(l->id, id) == 0)
                        return l;
 
        snprintf(buf, sizeof(buf), LIBDIR "/ip/link_%s.so", id);
@@ -142,10 +141,7 @@ static struct link_util *__get_link_kind(const char *id, bool slave)
                }
        }
 
-       if (slave)
-               snprintf(buf, sizeof(buf), "%s_slave_link_util", id);
-       else
-               snprintf(buf, sizeof(buf), "%s_link_util", id);
+       snprintf(buf, sizeof(buf), "%s_link_util", id);
        l = dlsym(dlh, buf);
        if (l == NULL)
                return NULL;
@@ -155,16 +151,6 @@ static struct link_util *__get_link_kind(const char *id, bool slave)
        return l;
 }
 
-struct link_util *get_link_kind(const char *id)
-{
-       return __get_link_kind(id, false);
-}
-
-struct link_util *get_link_slave_kind(const char *id)
-{
-       return __get_link_kind(id, true);
-}
-
 static int get_link_mode(const char *mode)
 {
        if (strcasecmp(mode, "default") == 0)
@@ -872,26 +858,18 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
 
        if (type) {
                struct rtattr *linkinfo;
-               char slavebuf[128], *ulinep = strchr(type, '_');
+               char *ulinep = strchr(type, '_');
                int iflatype;
 
                linkinfo = addattr_nest(&req.n, sizeof(req), IFLA_LINKINFO);
                addattr_l(&req.n, sizeof(req), IFLA_INFO_KIND, type,
                         strlen(type));
 
-               if (ulinep && !strcmp(ulinep, "_slave")) {
-                       strncpy(slavebuf, type, sizeof(slavebuf));
-                       slavebuf[sizeof(slavebuf) - 1] = '\0';
-                       ulinep = strchr(slavebuf, '_');
-                       /* check in case it was after sizeof(slavebuf) - 1*/
-                       if (ulinep)
-                               *ulinep = '\0';
-                       lu = get_link_slave_kind(slavebuf);
+               lu = get_link_kind(type);
+               if (ulinep && !strcmp(ulinep, "_slave"))
                        iflatype = IFLA_INFO_SLAVE_DATA;
-               } else {
-                       lu = get_link_kind(type);
+               else
                        iflatype = IFLA_INFO_DATA;
-               }
                if (lu && argc) {
                        struct rtattr *data = addattr_nest(&req.n,
                                                           sizeof(req), iflatype);
index 9c60dea8a27574bc3c892567cf06d9091e0b5d17..877e2d9ef817cf261b4a83ada6c3ba0f4e0b74bd 100644 (file)
@@ -130,10 +130,9 @@ static void bond_slave_print_help(struct link_util *lu, int argc, char **argv,
 }
 
 struct link_util bond_slave_link_util = {
-       .id             = "bond",
+       .id             = "bond_slave",
        .maxattr        = IFLA_BOND_SLAVE_MAX,
        .print_opt      = bond_slave_print_opt,
        .parse_opt      = bond_slave_parse_opt,
        .print_help     = bond_slave_print_help,
-       .slave          = true,
 };
index a44d4e41338773bb4085064b860ee560b0959f28..6c5c59a9524f487c383b5a96bf57d64c43f2c6bf 100644 (file)
@@ -293,10 +293,9 @@ static void bridge_slave_print_help(struct link_util *lu, int argc, char **argv,
 }
 
 struct link_util bridge_slave_link_util = {
-       .id             = "bridge",
+       .id             = "bridge_slave",
        .maxattr        = IFLA_BRPORT_MAX,
        .print_opt      = bridge_slave_print_opt,
        .parse_opt      = bridge_slave_parse_opt,
        .print_help     = bridge_slave_print_help,
-       .slave          = true,
 };
index 015b41e1e7b0ea98066161a1d4d9039858e80db6..a238b29068054512f5f5735bd1b1dd3aa5bdc3e2 100644 (file)
@@ -91,10 +91,9 @@ struct link_util vrf_link_util = {
 };
 
 struct link_util vrf_slave_link_util = {
-       .id             = "vrf",
+       .id             = "vrf_slave",
        .maxattr        = IFLA_VRF_PORT_MAX,
        .print_opt      = vrf_slave_print_opt,
-       .slave          = true,
 };
 
 /* returns table id if name is a VRF device */
index 127fa1e32bd1182e3227d7ec9c9ad9528a560737..c9252bb2419cd97996caab433a5c2adc35d760b4 100644 (file)
@@ -1265,5 +1265,4 @@ struct link_util macsec_link_util = {
        .parse_opt = macsec_parse_opt,
        .print_help = macsec_print_help,
        .print_opt = macsec_print_opt,
-       .slave = false,
 };