From cd6887a8eb84465d54ccf2065369796cca453315 Mon Sep 17 00:00:00 2001 From: darkcoven Date: Fri, 18 Oct 2013 22:59:08 +0200 Subject: [PATCH] Add error codes to handle bad replies and unknown errors --- cli/src/common.c | 8 ++++++++ lib/include/ngadmin.h | 4 +++- lib/src/mirror.c | 2 +- lib/src/network.c | 5 ++++- lib/src/vlan.c | 22 +++++++++++----------- 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/cli/src/common.c b/cli/src/common.c index 80f3f52..7d35301 100644 --- a/cli/src/common.c +++ b/cli/src/common.c @@ -40,6 +40,14 @@ void printErrCode (int err) printf("not implemented\n"); break; + case ERR_BADREPLY: + printf("bad reply from switch\n"); + break; + + case ERR_UNKNOWN: + printf("unknown error\n"); + break; + default: printf("unknown status code (%i)\n", err); } diff --git a/lib/include/ngadmin.h b/lib/include/ngadmin.h index a14917c..a98f429 100644 --- a/lib/include/ngadmin.h +++ b/lib/include/ngadmin.h @@ -48,7 +48,9 @@ enum { ERR_INVARG = -6, /**< invalid argument */ ERR_TIMEOUT = -7, /**< timeout */ ERR_MEM = -8, /**< out of memory */ - ERR_NOTIMPL = -9 /**< not implemented */ + ERR_NOTIMPL = -9, /**< not implemented */ + ERR_BADREPLY = -10, /**< bad reply */ + ERR_UNKNOWN = -11 /**< unknown error */ }; diff --git a/lib/src/mirror.c b/lib/src/mirror.c index be40738..8b76c1c 100644 --- a/lib/src/mirror.c +++ b/lib/src/mirror.c @@ -43,7 +43,7 @@ int ngadmin_getMirror (struct ngadmin *nga, char *ports) memset(ports, 0, 1 + sa->ports); } else if (am->outport > 0 && at->size >= 1 + sa->ports) { if (at->size < sizeof(struct attr_mirror) + sa->ports) { - ret = ERR_INVARG; + ret = ERR_BADREPLY; goto end; } ports[0] = am->outport; diff --git a/lib/src/network.c b/lib/src/network.c index e106596..b48461c 100644 --- a/lib/src/network.c +++ b/lib/src/network.c @@ -146,6 +146,9 @@ static int checkErrorCode (const struct nsdp_cmd *nc) { switch (nc->error) { + case 0: + return ERR_OK; + case ERROR_DENIED: return (nc->attr_error == ATTR_PASSWORD) ? ERR_BADPASS : ERR_DENIED; @@ -153,7 +156,7 @@ static int checkErrorCode (const struct nsdp_cmd *nc) return ERR_INVARG; default: - return ERR_OK; + return ERR_UNKNOWN; } } diff --git a/lib/src/vlan.c b/lib/src/vlan.c index 441e142..962f2f2 100644 --- a/lib/src/vlan.c +++ b/lib/src/vlan.c @@ -32,7 +32,7 @@ int ngadmin_getVLANType (struct ngadmin *nga, int *t) *t = VLAN_DISABLED; if (attr->first == NULL) { - ret = ERR_INVARG; + ret = ERR_BADREPLY; goto end; } at = attr->first->data; @@ -93,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; } @@ -104,7 +104,7 @@ int ngadmin_getVLANPortConf (struct ngadmin *nga, unsigned char *ports) avc = at->data; if (at->size < sizeof(struct attr_vlan_conf) + sa->ports) { - ret = ERR_INVARG; + ret = ERR_BADREPLY; goto end; } @@ -155,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; } @@ -168,7 +168,7 @@ int ngadmin_setVLANPortConf (struct ngadmin *nga, const unsigned char *ports) avc_old = at->data; if (at->size < sizeof(struct attr_vlan_conf) + sa->ports) { - ret = ERR_INVARG; + ret = ERR_BADREPLY; free(avc_new); goto end; } @@ -241,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; } @@ -253,7 +253,7 @@ int ngadmin_getVLANDotAllConf (struct ngadmin *nga, unsigned short *vlans, unsig avc = at->data; if (at->size < sizeof(struct attr_vlan_conf) + sa->ports) { - ret = ERR_INVARG; + ret = ERR_BADREPLY; goto end; } @@ -303,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; } @@ -314,7 +314,7 @@ int ngadmin_getVLANDotConf (struct ngadmin *nga, unsigned short vlan, unsigned c avc = at->data; if (at->size < sizeof(struct attr_vlan_conf) + sa->ports) { - ret = ERR_INVARG; + ret = ERR_BADREPLY; goto end; } @@ -375,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; + ret = ERR_BADREPLY; goto end; } } -- 2.39.2