]> git.sur5r.net Git - ngadmin/commitdiff
Merge branch 'autotools'
authordarkcoven <admin@darkcoven.tk>
Fri, 11 Oct 2013 19:48:29 +0000 (21:48 +0200)
committerdarkcoven <admin@darkcoven.tk>
Fri, 11 Oct 2013 19:48:29 +0000 (21:48 +0200)
Conflicts:
cli/src/admin.c

cli/src/admin.c
cli/src/com_vlan.c
lib/src/libconf.c
lib/src/network.c
lib/src/network.h
lib/src/vlan.c
wireshark/nsdp.lua

index dbd30bbaeaf260fca48659de9cdf1fec1e376473..73ea79c7a3cc143a8cdcb5a48cadb70d857de0ca 100644 (file)
@@ -21,8 +21,6 @@
 #define MAXCOM 32
 
 
-int main_loop_continue;
-
 
 static const struct TreeNode* getSubCom (char **com, int n, int *t)
 {
@@ -115,6 +113,7 @@ static char** my_completion (const char *text, int start, int end UNUSED)
 #endif /* HAVE_LIBREADLINE */
 
 
+int main_loop_continue;
 static struct ngadmin *nga;
 static sigjmp_buf jmpbuf;
 static struct termios orig_term;
@@ -133,7 +132,7 @@ NORET static void handler (int sig)
                current_term.c_lflag |= ECHO;
                tcsetattr(STDIN_FILENO, TCSANOW, &current_term);
                
-               if (!batch)
+               if (!batch && main_loop_continue)
                        siglongjmp(jmpbuf, 1);
        
        default:
@@ -159,7 +158,7 @@ static int pre_login (const struct ether_addr *mac, int retries)
                err = ngadmin_scan(nga);
                if (err < 0) {
                        printErrCode(err);
-                       continue;
+                       return err;
                }
                
                /* search switch with requested MAC */
@@ -199,9 +198,9 @@ int main (int argc, char **argv)
                {"batch", no_argument, NULL, 'a'},
                {"keep-broadcasting", no_argument, NULL, 'b'},
                {"force-interface", no_argument, NULL, 'f'},
-               {"global-broadcast", no_argument, NULL, 'g'},
                {"help", no_argument, NULL, 'h'},
                {"interface", required_argument, NULL, 'i'},
+               {"local-broadcast", no_argument, NULL, 'l'},
                {"mac", required_argument, NULL, 'm'},
                {"password", required_argument, NULL, 'p'},
                {"retries", required_argument, NULL, 'r'},
@@ -211,7 +210,7 @@ int main (int argc, char **argv)
        char *line, *com[MAXCOM];
        const char *iface = "eth0", *password = NULL;
        float timeout = 0.f;
-       bool kb = false, force = false, global = false;
+       bool kb = false, force = false, global = true;
        struct timeval tv;
        const struct TreeNode *cur, *next;
        struct ether_addr *mac = NULL;
@@ -228,7 +227,7 @@ int main (int argc, char **argv)
        
        opterr = 0;
        
-       while ((n = getopt_long(argc, argv, "abfghi:m:p:r:t:", opts, NULL)) != -1) {
+       while ((n = getopt_long(argc, argv, "abfhi:lm:p:r:t:", opts, NULL)) != -1) {
                switch (n) {
                
                case 'a':
@@ -243,10 +242,6 @@ int main (int argc, char **argv)
                        force = true;
                        break;
                
-               case 'g':
-                       global = true;
-                       break;
-               
                case 'h':
                        printf("usage: %s [-a] [-b] [-f] [-g] [-i <interface>] [-m <MAC>] [-p <password>]\n", argv[0]);
                        goto end;
@@ -255,6 +250,10 @@ int main (int argc, char **argv)
                        iface = optarg;
                        break;
                
+               case 'l':
+                       global = false;
+                       break;
+               
                case 'm':
                        mac = ether_aton(optarg);
                        if (mac == NULL) {
@@ -306,13 +305,13 @@ int main (int argc, char **argv)
        }
        
        
-       if (kb && ngadmin_setKeepBroadcasting(nga, true) != ERR_OK)
+       if (ngadmin_setKeepBroadcasting(nga, kb) != ERR_OK)
                goto end;
        
        if (force && ngadmin_forceInterface(nga) != ERR_OK)
                goto end;
        
-       if (global && ngadmin_useGlobalBroadcast(nga, true) != ERR_OK)
+       if (ngadmin_useGlobalBroadcast(nga, global) != ERR_OK)
                goto end;
        
        /* non-TTY inputs are automatically set to batch mode */
@@ -329,7 +328,13 @@ int main (int argc, char **argv)
        if (mac != NULL && pre_login(mac, retries) != 0)
                goto end;
        
-       if (!batch) {
+       if (batch) {
+               /* in batch mode, we must be logged to continue */
+               if (ngadmin_getCurrentSwitch(nga) == NULL) {
+                       printf("must be logged\n");
+                       goto end;
+               }
+       } else {
 #ifdef HAVE_LIBREADLINE
                /* initialize readline functions */
                rl_attempted_completion_function = my_completion;
@@ -340,7 +345,6 @@ int main (int argc, char **argv)
        }
        
        main_loop_continue = 1;
-       
        while (main_loop_continue) {
                /* read user input */
                line = NULL;
index 34968152b9fe9a6963cd9e4d59da26154ad7793f..0baa1d5d0c32699d02278abe95c0e490a52974b9 100644 (file)
@@ -339,6 +339,7 @@ int do_vlan_mode_set (int argc, const char **argv, struct ngadmin *nga)
        if (argc == 0) {
                printf(
                "usage: vlan mode set <mode>\n"
+               "0 - disabled\n"
                "1 - basic port based\n"
                "2 - advanced port based\n"
                "3 - basic 802.1Q\n"
@@ -353,7 +354,7 @@ int do_vlan_mode_set (int argc, const char **argv, struct ngadmin *nga)
        }
        
        mode = strtoul(argv[0], NULL, 0);
-       if (mode < 1 || mode > 4) {
+       if (mode < VLAN_DISABLED || mode > VLAN_DOT_ADV) {
                printf("mode out of range\n");
                return 1;
        }
index e26a7224e23ba964210d635e20cffc843c060c91..62cb6ff54698a33c86ee0ebf4830eeadf8392b66 100644 (file)
@@ -19,6 +19,7 @@ struct ngadmin* ngadmin_init (const char *iface)
        /* allocate main structure */
        nga = malloc(sizeof(struct ngadmin));
        memset(nga, 0, sizeof(struct ngadmin));
+       nga->globalbroad = true;
        
        strncpy(nga->iface, iface, IFNAMSIZ - 1);
        
@@ -76,9 +77,10 @@ int ngadmin_useGlobalBroadcast (struct ngadmin *nga, bool value)
        if (nga == NULL)
                return ERR_INVARG;
        
-       nga->globalbroad = value;
-       
-       return ERR_OK;
+       if (setBroadcastType(nga, value) == 0)
+               return ERR_OK;
+       else
+               return ERR_NET;
 }
 
 
index 0306d0aa5462601489b8770b71298069a6b87973..1e0211bce5992aab7f2c3335002fde1282ddd090 100644 (file)
@@ -30,16 +30,7 @@ int startNetwork (struct ngadmin *nga)
        
        memset(&ifr, 0, sizeof(struct ifreq));
        strncpy(ifr.ifr_name, nga->iface, IFNAMSIZ - 1);
-       
-       /* get the interface broadcast address */
-       ret = ioctl(nga->sock, SIOCGIFBRDADDR, &ifr);
-       if (ret < 0) {
-               perror("ioctl(SIOCGIFBRDADDR)");
-               close(nga->sock);
-               return ret;
-       }
-       nga->brd = (*(struct sockaddr_in*)&ifr.ifr_addr).sin_addr;
-       
+
        /* get the interface MAC address */
        ret = ioctl(nga->sock, SIOCGIFHWADDR, &ifr);
        if (ret < 0) {
@@ -82,6 +73,36 @@ int startNetwork (struct ngadmin *nga)
 }
 
 
+int setBroadcastType (struct ngadmin *nga, bool value)
+{
+       int ret;
+       struct ifreq ifr;
+       
+       
+       nga->globalbroad = value;
+       if (value) {
+               nga->brd.s_addr = (in_addr_t)0;
+               return 0;
+       }
+       
+       memset(&ifr, 0, sizeof(struct ifreq));
+       strncpy(ifr.ifr_name, nga->iface, IFNAMSIZ - 1);
+       
+       /* get the interface broadcast address */
+       ret = ioctl(nga->sock, SIOCGIFBRDADDR, &ifr);
+       if (ret < 0) {
+               perror("ioctl(SIOCGIFBRDADDR)");
+               nga->brd.s_addr = (in_addr_t)0;
+               nga->globalbroad = true;
+               return ret;
+       }
+       
+       nga->brd = (*(struct sockaddr_in*)&ifr.ifr_addr).sin_addr;
+       
+       return 0;
+}
+
+
 int stopNetwork (struct ngadmin *nga)
 {
        return close(nga->sock);
index c071f10a83258be4a35738001a37e82a17c8af4a..5137c98a4990fa0bb81166c591fb65efc0fbd1de 100644 (file)
@@ -10,6 +10,9 @@
 int startNetwork (struct ngadmin *nga);
 
 
+int setBroadcastType (struct ngadmin *nga, bool value);
+
+
 int stopNetwork (struct ngadmin *nga);
 
 
index dda8ce5363757e6dbfff13d90249cb1419283a76..2e6b2f692a7a2ec6c4d6b33cf9d667f5d437361e 100644 (file)
@@ -31,11 +31,12 @@ int ngadmin_getVLANType (struct ngadmin *nga, int *t)
        
        *t = VLAN_DISABLED;
        
-       if (attr->first != NULL) {
-               at = attr->first->data;
-               *t =(int)*(char*)at->data;
+       if (attr->first == NULL) {
+               ret = ERR_INVARG;
+               goto end;
        }
-       
+       at = attr->first->data;
+       *t =(int)*(char*)at->data;
        
 end:
        destroyList(attr, (void(*)(void*))freeAttr);
@@ -50,7 +51,7 @@ int ngadmin_setVLANType (struct ngadmin *nga, int t)
        List *attr;
        
        
-       if (nga == NULL || t < 1 || t > 4)
+       if (nga == NULL || t < VLAN_DISABLED || t > VLAN_DOT_ADV)
                return ERR_INVARG;
        else if (nga->current == NULL)
                return ERR_NOTLOG;
index 52a94b2223d49a405df399354f4323a3a60d89ba..53aea70c3df3e225d40af26989dbdf89209224fa 100644 (file)
@@ -61,6 +61,7 @@ local bitrates_codes = {
 
 
 local vlan_type_codes = {
+       [0] = "disabled",
        [1] = "port basic",
        [2] = "port advanced",
        [3] = "802.1Q basic",