]> git.sur5r.net Git - ngadmin/blobdiff - lib/src/vlan.c
Add error codes to handle bad replies and unknown errors
[ngadmin] / lib / src / vlan.c
index dda8ce5363757e6dbfff13d90249cb1419283a76..962f2f2e0c5dbc280aa8396ca708c1f398447443 100644 (file)
@@ -1,8 +1,8 @@
 
 #include <ngadmin.h>
 
-#include <attr.h>
-#include <protocol.h>
+#include <nsdp/attr.h>
+#include <nsdp/protocol.h>
 
 #include "lib.h"
 #include "network.h"
@@ -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_BADREPLY;
+               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;
@@ -92,7 +93,7 @@ int ngadmin_getVLANPortConf (struct ngadmin *nga, unsigned char *ports)
        filterAttributes(attr, ATTR_VLAN_PORT_CONF, ATTR_END);
        
        if (attr->first == NULL) {
-               ret = ERR_INVARG;
+               ret = ERR_BADREPLY;
                goto end;
        }
        
@@ -102,8 +103,8 @@ int ngadmin_getVLANPortConf (struct ngadmin *nga, unsigned char *ports)
                at = ln->data;
                avc = at->data;
 
-               if (at->size != sizeof(struct attr_vlan_conf) + sa->ports) {
-                       ret = ERR_INVARG;
+               if (at->size < sizeof(struct attr_vlan_conf) + sa->ports) {
+                       ret = ERR_BADREPLY;
                        goto end;
                }
                
@@ -154,7 +155,7 @@ int ngadmin_setVLANPortConf (struct ngadmin *nga, const unsigned char *ports)
        filterAttributes(conf_old, ATTR_VLAN_PORT_CONF, ATTR_END);
        
        if (conf_old->first == NULL) {
-               ret = ERR_INVARG;
+               ret = ERR_BADREPLY;
                goto end;
        }
        
@@ -166,8 +167,8 @@ int ngadmin_setVLANPortConf (struct ngadmin *nga, const unsigned char *ports)
                at = ln->data;
                avc_old = at->data;
                
-               if (at->size != sizeof(struct attr_vlan_conf) + sa->ports) {
-                       ret = ERR_INVARG;
+               if (at->size < sizeof(struct attr_vlan_conf) + sa->ports) {
+                       ret = ERR_BADREPLY;
                        free(avc_new);
                        goto end;
                }
@@ -240,7 +241,7 @@ int ngadmin_getVLANDotAllConf (struct ngadmin *nga, unsigned short *vlans, unsig
        filterAttributes(attr, ATTR_VLAN_DOT_CONF, ATTR_END);
        
        if (attr->first == NULL) {
-               ret = ERR_INVARG;
+               ret = ERR_BADREPLY;
                goto end;
        }
        
@@ -251,8 +252,8 @@ int ngadmin_getVLANDotAllConf (struct ngadmin *nga, unsigned short *vlans, unsig
                at = ln->data;
                avc = at->data;
                
-               if (at->size != sizeof(struct attr_vlan_conf) + sa->ports) {
-                       ret = ERR_INVARG;
+               if (at->size < sizeof(struct attr_vlan_conf) + sa->ports) {
+                       ret = ERR_BADREPLY;
                        goto end;
                }
                
@@ -302,7 +303,7 @@ int ngadmin_getVLANDotConf (struct ngadmin *nga, unsigned short vlan, unsigned c
        filterAttributes(attr, ATTR_VLAN_DOT_CONF, ATTR_END);
        
        if (attr->first == NULL) {
-               ret = ERR_INVARG;
+               ret = ERR_BADREPLY;
                goto end;
        }
        
@@ -312,8 +313,8 @@ int ngadmin_getVLANDotConf (struct ngadmin *nga, unsigned short vlan, unsigned c
                at = ln->data;
                avc = at->data;
                
-               if (at->size != sizeof(struct attr_vlan_conf) + sa->ports) {
-                       ret = ERR_INVARG;
+               if (at->size < sizeof(struct attr_vlan_conf) + sa->ports) {
+                       ret = ERR_BADREPLY;
                        goto end;
                }
                
@@ -374,12 +375,12 @@ int ngadmin_setVLANDotConf (struct ngadmin *nga, unsigned short vlan, const unsi
                
                /* check if the switch is in 802.1Q mode */
                if (attr->first == NULL) {
-                       ret = ERR_INVARG;
+                       ret = ERR_BADREPLY;
                        goto end;
                } else {
                        at = attr->first->data;
-                       if (at->size != sizeof(struct attr_vlan_conf) + sa->ports) {
-                               ret = ERR_INVARG;
+                       if (at->size < sizeof(struct attr_vlan_conf) + sa->ports) {
+                               ret = ERR_BADREPLY;
                                goto end;
                        }
                }
@@ -435,11 +436,14 @@ int ngadmin_getAllPVID (struct ngadmin *nga, unsigned short *ports)
        struct attr *at;
        int ret = ERR_OK;
        struct attr_pvid *ap;
+       struct swi_attr *sa;
        
        
        if (nga == NULL || ports == NULL)
                return ERR_INVARG;
-       else if (nga->current == NULL)
+       
+       sa = nga->current;
+       if (sa == NULL)
                return ERR_NOTLOG;
        
        
@@ -451,12 +455,13 @@ int ngadmin_getAllPVID (struct ngadmin *nga, unsigned short *ports)
        
        filterAttributes(attr, ATTR_VLAN_PVID, ATTR_END);
        
-       memset(ports, 0, nga->current->ports * sizeof(unsigned short));
+       memset(ports, 0, sa->ports * sizeof(unsigned short));
        
        for (ln = attr->first; ln != NULL; ln = ln->next) {
                at = ln->data;
                ap = at->data;
-               ports[ap->port - 1] = ap->vlan;
+               if (ap->port <= sa->ports)
+                       ports[ap->port - 1] = ap->vlan;
        }