#include <netinet/ether.h>
#include <sys/ioctl.h>
-#include "attr.h"
-#include "protocol.h"
+#include <attr.h>
+#include <protocol.h>
+
#include "network.h"
}
-int recvNgPacket (struct ngadmin *nga, char code, unsigned char *error, unsigned short *attr_error, List *attr, unsigned short filter_attr)
+int recvNgPacket (struct ngadmin *nga, char code, unsigned char *error, unsigned short *attr_error, List *attr)
{
char buffer[1500];
struct ng_packet np;
if (ntohs(remote.sin_port) != SWITCH_PORT ||
len < (int)sizeof(struct ng_header) ||
!validateNgHeader(np.nh, code, &nga->localmac, sa == NULL ? NULL : &sa->mac, nga->seq) ||
- extractPacketAttributes(&np, error, attr_error, attr, filter_attr, sa == NULL ? 0 : sa->ports) < 0)
+ extractPacketAttributes(&np, attr, sa == NULL ? 0 : sa->ports) < 0)
continue;
+ if (error != NULL)
+ *error = np.nh->error;
+ if (attr_error != NULL)
+ *attr_error = ntohs(np.nh->attr);
+
len = 0;
break;
}
}
-int readRequest (struct ngadmin *nga, List *attr, unsigned short filter_attr)
+int readRequest (struct ngadmin *nga, List *attr)
{
int i, ret = ERR_OK;
unsigned char err;
clearList(attr, (void(*)(void*))freeAttr);
if (i >= 0)
- i = recvNgPacket(nga, CODE_READ_REP, &err, &attr_error, attr, filter_attr);
+ i = recvNgPacket(nga, CODE_READ_REP, &err, &attr_error, attr);
if (i == -EINVAL) {
ret = ERR_INVARG;
clearList(attr, (void(*)(void*))freeAttr);
if (i >= 0)
- i = recvNgPacket(nga, CODE_WRITE_REP, &err, &attr_error, attr, ATTR_END);
+ i = recvNgPacket(nga, CODE_WRITE_REP, &err, &attr_error, attr);
if (i == -EINVAL) {
ret = ERR_INVARG;
#include <ngadmin.h>
+#include <attr.h>
+#include <protocol.h>
+
#include "lib.h"
#include "network.h"
-#include "attr.h"
-#include "protocol.h"
-
static const struct timeval default_timeout = {.tv_sec = 4, .tv_usec = 0};
/* try to receive any packets until timeout */
swiList = createEmptyList();
/* FIXME: end after timeout whatever received packet is good or not */
- while (recvNgPacket(nga, CODE_READ_REP, NULL, NULL, attr, ATTR_END) >= 0) {
+ while (recvNgPacket(nga, CODE_READ_REP, NULL, NULL, attr) >= 0) {
sa = malloc(sizeof(struct swi_attr));
if (sa == NULL)
return ERR_MEM;
attr = createEmptyList();
pushBackList(attr, newAttr(ATTR_PASSWORD, strlen(nga->password), strdup(nga->password)));
- ret = readRequest(nga, attr, ATTR_END);
+ ret = readRequest(nga, attr);
if (ret == ERR_OK ) {
/* login succeeded */
/* TODO: if keep broadcasting is disabled, connect() the UDP
attr = createEmptyList();
pushBackList(attr, newEmptyAttr(ATTR_PORT_STATUS));
- ret = readRequest(nga, attr, ATTR_PORT_STATUS);
+ ret = readRequest(nga, attr);
if (ret != ERR_OK)
goto end;
+ filterAttributes(attr, ATTR_PORT_STATUS, ATTR_END);
+
memset(ports, SPEED_UNK, nga->current->ports);
for (ln = attr->first; ln != NULL; ln = ln->next) {
attr = createEmptyList();
pushBackList(attr, newEmptyAttr(ATTR_PORT_STATISTICS));
- ret = readRequest(nga, attr, ATTR_PORT_STATISTICS);
+ ret = readRequest(nga, attr);
if (ret != ERR_OK)
goto end;
+ filterAttributes(attr, ATTR_PORT_STATISTICS, ATTR_END);
+
memset(ps, 0, nga->current->ports * sizeof(struct port_stats));
for (ln = attr->first; ln != NULL; ln = ln->next) {
attr = createEmptyList();
pushBackList(attr, newEmptyAttr(ATTR_STORM_ENABLE));
- ret = readRequest(nga, attr, ATTR_STORM_ENABLE);
+ ret = readRequest(nga, attr);
if (ret != ERR_OK)
goto end;
+ filterAttributes(attr, ATTR_STORM_ENABLE, ATTR_END);
+
*s = 0;
if (attr->first != NULL) {
attr = createEmptyList();
pushBackList(attr, newEmptyAttr(ATTR_STORM_BITRATE));
- ret = readRequest(nga, attr, ATTR_STORM_BITRATE);
+ ret = readRequest(nga, attr);
if (ret != ERR_OK)
goto end;
+ filterAttributes(attr, ATTR_STORM_BITRATE, ATTR_END);
+
for (port = 0; port < nga->current->ports; port++)
ports[port] = BITRATE_UNSPEC;
attr = createEmptyList();
pushBackList(attr, newEmptyAttr(ATTR_BITRATE_INPUT));
pushBackList(attr, newEmptyAttr(ATTR_BITRATE_OUTPUT));
- ret = readRequest(nga, attr, ATTR_END);
+ ret = readRequest(nga, attr);
if (ret != ERR_OK)
goto end;
attr = createEmptyList();
pushBackList(attr, newEmptyAttr(ATTR_QOS_TYPE));
- ret = readRequest(nga, attr, ATTR_QOS_TYPE);
+ ret = readRequest(nga, attr);
if (ret != ERR_OK)
goto end;
+ filterAttributes(attr, ATTR_QOS_TYPE, ATTR_END);
+
*s = 0;
if (attr->first != NULL) {
attr = createEmptyList();
pushBackList(attr, newEmptyAttr(ATTR_QOS_CONFIG));
- ret = readRequest(nga, attr, ATTR_QOS_CONFIG);
+ ret = readRequest(nga, attr);
if (ret < 0)
goto end;
+ filterAttributes(attr, ATTR_QOS_CONFIG, ATTR_END);
+
for (port = 0; port < nga->current->ports; port++)
ports[port] = PRIO_UNSPEC;
attr = createEmptyList();
pushBackList(attr, newEmptyAttr(ATTR_MIRROR));
- ret = readRequest(nga, attr, ATTR_MIRROR);
+ ret = readRequest(nga, attr);
if (ret < 0)
goto end;
+ filterAttributes(attr, ATTR_MIRROR, ATTR_END);
+
memset(ports, 0, 1 + nga->current->ports);
if (attr->first != NULL) {
pushBackList(attr, newEmptyAttr(ATTR_IGMP_ENABLE_VLAN));
- ret = readRequest(nga, attr, ATTR_IGMP_ENABLE_VLAN);
+ ret = readRequest(nga, attr);
if (ret < 0)
goto end;
+ filterAttributes(attr, ATTR_IGMP_ENABLE_VLAN, ATTR_END);
+
if (attr->first != NULL) {
at = attr->first->data;
aiv = at->data;
pushBackList(attr, newEmptyAttr(ATTR_IGMP_BLOCK_UNK));
- ret = readRequest(nga, attr, ATTR_IGMP_BLOCK_UNK);
+ ret = readRequest(nga, attr);
if (ret < 0)
goto end;
+ filterAttributes(attr, ATTR_IGMP_BLOCK_UNK, ATTR_END);
+
if (attr->first != NULL) {
at = attr->first->data;
ic->block = *(char*)at->data;
pushBackList(attr, newEmptyAttr(ATTR_IGMP_VALID_V3));
- ret = readRequest(nga, attr, ATTR_IGMP_VALID_V3);
+ ret = readRequest(nga, attr);
if (ret < 0)
goto end;
+ filterAttributes(attr, ATTR_IGMP_VALID_V3, ATTR_END);
+
if (attr->first != NULL) {
at = attr->first->data;
ic->validate = *(char*)at->data;
/* the list is destroyed by writeRequest, so we need to recreate it */
attr = createEmptyList();
pushBackList(attr, newByteAttr(ATTR_CABLETEST_RESULT, ct[i].port));
- ret = readRequest(nga, attr, ATTR_CABLETEST_RESULT);
+ ret = readRequest(nga, attr);
if (ret < 0)
goto end;
+ filterAttributes(attr, ATTR_CABLETEST_RESULT, ATTR_END);
+
for (ln = attr->first; ln != NULL; ln = ln->next) {
at = ln->data;
acr = at->data;
attr = createEmptyList();
pushBackList(attr, newEmptyAttr(ATTR_VLAN_TYPE));
- ret=readRequest(nga, attr, ATTR_VLAN_TYPE);
+ ret=readRequest(nga, attr);
if (ret != ERR_OK)
goto end;
+ filterAttributes(attr, ATTR_VLAN_TYPE, ATTR_END);
+
*t = VLAN_DISABLED;
if (attr->first != NULL) {
attr = createEmptyList();
pushBackList(attr, newEmptyAttr(ATTR_VLAN_DOT_CONF));
- ret = readRequest(nga, attr, ATTR_VLAN_DOT_CONF);
+ ret = readRequest(nga, attr);
if (ret != ERR_OK)
goto end;
+ filterAttributes(attr, ATTR_VLAN_DOT_CONF, ATTR_END);
+
memset(vlans, 0, total * sizeof(unsigned short));
memset(ports, 0, total * nga->current->ports);
attr = createEmptyList();
pushBackList(attr, newShortAttr(ATTR_VLAN_DOT_CONF, vlan));
- ret = readRequest(nga, attr, ATTR_END);
+ ret = readRequest(nga, attr);
if (ret != ERR_OK)
goto end;
+ filterAttributes(attr, ATTR_VLAN_DOT_CONF, ATTR_END);
+
memset(ports, 0, nga->current->ports);
for (ln = attr->first; ln != NULL; ln = ln->next) {
if (memchr(ports, VLAN_UNSPEC, sa->ports) != NULL) {
pushBackList(attr, newShortAttr(ATTR_VLAN_DOT_CONF, vlan));
- ret = readRequest(nga, attr, ATTR_VLAN_DOT_CONF);
+ ret = readRequest(nga, attr);
if (ret != ERR_OK)
goto end;
+ filterAttributes(attr, ATTR_VLAN_DOT_CONF, ATTR_END);
+
if (attr->first != NULL) {
at = attr->first->data;
memcpy(avd, at->data, sizeof(struct attr_vlan_dot) + sa->ports);
attr = createEmptyList();
pushBackList(attr, newEmptyAttr(ATTR_VLAN_PVID));
- ret = readRequest(nga, attr, ATTR_VLAN_PVID);
+ ret = readRequest(nga, attr);
if (ret != ERR_OK)
goto end;
+ filterAttributes(attr, ATTR_VLAN_PVID, ATTR_END);
+
memset(ports, 0, nga->current->ports * sizeof(unsigned short));
for (ln = attr->first; ln != NULL; ln = ln->next) {