Lib: fixed the issue when changing only a part of network configuration.
}
- printf("QOS mode: ");
+ printf("QoS mode: ");
if ( s==QOS_DOT ) {
printf("802.1p\n");
+bool do_vlan_8021q_vlan_del (int nb, const char **com, struct ngadmin *nga) {
+
+ const struct swi_attr *sa;
+ unsigned short vlan;
+ int i;
+
+
+ if ( nb!=1 ) {
+ printf("Usage: vlan 8021q vlan del <vlan>\n");
+ return false;
+ }
+
+ if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
+ printf("must be logged\n");
+ return false;
+ }
+
+ vlan=strtoul(com[0], NULL, 0);
+
+ if ( vlan<1 || vlan>VLAN_MAX ) {
+ printf("vlan out of range\n");
+ return false;
+ }
+
+
+ i=ngadmin_VLANDestroy(nga, vlan);
+ printErrCode(i);
+
+
+ return true;
+
+}
+
+
+
bool do_vlan_mode_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
int i, t, ret=true;
+bool do_vlan_pvid_set (int nb, const char **com, struct ngadmin *nga) {
+
+ const struct swi_attr *sa;
+ unsigned char port;
+ unsigned short vlan;
+ int i;
+
+
+ if ( nb!=2 ) {
+ printf("Usage: vlan pvid set <port> <vlan>\n");
+ return false;
+ }
+
+ if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
+ printf("must be logged\n");
+ return false;
+ }
+
+ port=strtoul(com[0], NULL, 0);
+ vlan=strtoul(com[1], NULL, 0);
+
+ if ( port<1 || port>sa->ports ) {
+ printf("port out of range\n");
+ return false;
+ }
+
+ if ( vlan<1 || vlan>VLAN_MAX ) {
+ printf("vlan out of range\n");
+ return false;
+ }
+
+
+ i=ngadmin_setPVID(nga, port, vlan);
+ printErrCode(i);
+
+
+ return true;
+
+}
+
+
+
bool do_vlan_pvid_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
unsigned short *ports=NULL;
}
ports=malloc(sa->ports*sizeof(unsigned short));
- i=ngadmin_getPVID(nga, ports);
+ i=ngadmin_getAllPVID(nga, ports);
if ( i!=ERR_OK ) {
printErrCode(i);
ret=false;
// vlan
bool do_vlan_8021q_show (int nb, const char **com, struct ngadmin *nga);
+bool do_vlan_8021q_vlan_del (int nb, const char **com, struct ngadmin *nga);
bool do_vlan_mode_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga);
+bool do_vlan_pvid_set (int nb, const char **com, struct ngadmin *nga);
bool do_vlan_pvid_show (int nb, const char **com, struct ngadmin *nga);
COM_TERM(show, do_vlan_8021q_show, true)
COM_START(vlan)
COM_TERM(add, NULL, true)
- COM_TERM(del, NULL, true)
+ COM_TERM(del, do_vlan_8021q_vlan_del, true)
COM_TERM(flush, NULL, true)
COM_END
COM_END
COM_START(port)
COM_END
COM_START(pvid)
- COM_TERM(set, NULL, true)
+ COM_TERM(set, do_vlan_pvid_set, true)
COM_TERM(show, do_vlan_pvid_show, false)
COM_END
COM_END
printf("Num\tMac\t\t\tProduct\t\tName\t\t\tIP/mask\t\t\tDHCP\tPorts\tFirmware\n");
for (i=0; i<nb; ++i) {
- printf("%i\t%s\t%s\t\t%s\t%s/", i, ether_ntoa(&sa[i].mac), sa[i].product, sa[i].name, inet_ntoa(sa[i].nc.ip));
+ printf("%i\t%s\t%s\t%s\t\t%s/", i, ether_ntoa(&sa[i].mac), sa[i].product, sa[i].name, inet_ntoa(sa[i].nc.ip));
printf("%s\t%s\t%i\t%s\n", inet_ntoa(sa[i].nc.netmask), ( sa[i].nc.dhcp ? "Yes" : "No" ), sa[i].ports, sa[i].firmware);
}
#define VLAN_UNTAGGED 1
#define VLAN_TAGGED 2
+#define VLAN_MAX 4093
+
#define QOS_PORT 1
#define QOS_DOT 2
int ngadmin_getVLANType (struct ngadmin *nga, int *t) EXPORT;
+//
+int ngadmin_setVLANType (struct ngadmin *nga, int t) EXPORT;
+
+
//
int ngadmin_getVLANDotAllConf (struct ngadmin *nga, unsigned short *vlans, unsigned char *ports, int *nb) EXPORT;
//
-int ngadmin_getPVID (struct ngadmin *nga, unsigned short *ports) EXPORT;
+int ngadmin_setVLANDotConf (struct ngadmin *nga, unsigned short vlan, const unsigned char *ports) EXPORT;
+
+
+//
+int ngadmin_VLANDestroy (struct ngadmin *nga, unsigned short vlan) EXPORT;
+
+
+//
+int ngadmin_getAllPVID (struct ngadmin *nga, unsigned short *ports) EXPORT;
+
+
+//
+int ngadmin_setPVID (struct ngadmin *nga, unsigned char port, unsigned short vlan) EXPORT;
+
//
int startNetwork (struct ngadmin *nga);
pushBackList(attr, newByteAttr(ATTR_DHCP, 1));
} else {
pushBackList(attr, newByteAttr(ATTR_DHCP, 0));
+ // only add non-null values
if ( nc->ip.s_addr!=0 ) pushBackList(attr, newAddrAttr(ATTR_IP, nc->ip));
if ( nc->netmask.s_addr!=0 ) pushBackList(attr, newAddrAttr(ATTR_NETMASK, nc->netmask));
if ( nc->gw.s_addr!=0 ) pushBackList(attr, newAddrAttr(ATTR_GATEWAY, nc->gw));
}
- if ( nc->dhcp ) {
- sa->nc.dhcp=true;
- } else {
- memcpy(&sa->nc, nc, sizeof(struct net_conf));
+ // update local values
+ sa->nc.dhcp=nc->dhcp;
+ if ( !nc->dhcp ) {
+ if ( nc->ip.s_addr!=0 ) sa->nc.ip=nc->ip;
+ if ( nc->netmask.s_addr!=0 ) sa->nc.netmask=nc->netmask;
+ if ( nc->gw.s_addr!=0 ) sa->nc.gw=nc->gw;
}
+// -------------------------------------------------
+int ngadmin_setVLANType (struct ngadmin *nga, int t) {
+
+ List *attr;
+ struct swi_attr *sa;
+
+
+ if ( nga==NULL || t<1 || t>4 ) {
+ return ERR_INVARG;
+ } else if ( (sa=nga->current)==NULL ) {
+ return ERR_NOTLOG;
+ }
+
+
+ attr=createEmptyList();
+ pushBackList(attr, newByteAttr(ATTR_VLAN_TYPE, t));
+
+
+ return writeRequest(nga, attr);
+
+}
+
+
+
// ------------------------------------------------------------------------------------------------------
int ngadmin_getVLANDotAllConf (struct ngadmin *nga, unsigned short *vlans, unsigned char *ports, int *nb) {
-// -------------------------------------------------------------
-int ngadmin_getPVID (struct ngadmin *nga, unsigned short *ports) {
+// ----------------------------------------------------------------------------------------------
+int ngadmin_setVLANDotConf (struct ngadmin *nga, unsigned short vlan, const unsigned char *ports) {
+
+ List *attr;
+ struct swi_attr *sa;
+ int i;
+ char *p;
+
+
+ if ( nga==NULL || ports==NULL || vlan<1 || vlan>VLAN_MAX ) {
+ return ERR_INVARG;
+ } else if ( (sa=nga->current)==NULL ) {
+ return ERR_NOTLOG;
+ }
+
+
+
+ attr=createEmptyList();
+ p=malloc(4);
+ *(unsigned short*)p=htons(vlan);
+
+ for (i=1; i<=sa->ports; ++i) {
+ if ( ports[i-1]==VLAN_TAGGED ) { // tagged
+ p[3]|=(1<<(sa->ports-i));
+ } else if ( ports[i-1]==VLAN_UNTAGGED ) { // untagged
+ p[2]|=(1<<(sa->ports-i));
+ }
+ }
+
+ // tagged ports must be also present in untagged ports
+ p[2]|=ports[3];
+
+
+ pushBackList(attr, newAttr(ATTR_VLAN_DOT_CONF, 4, p));
+
+
+ return writeRequest(nga, attr);
+
+}
+
+
+
+// ---------------------------------------------------------------
+int ngadmin_VLANDestroy (struct ngadmin *nga, unsigned short vlan) {
+
+ List *attr;
+ struct swi_attr *sa;
+
+
+ if ( nga==NULL || vlan<1 || vlan>VLAN_MAX ) {
+ return ERR_INVARG;
+ } else if ( (sa=nga->current)==NULL ) {
+ return ERR_NOTLOG;
+ }
+
+
+ attr=createEmptyList();
+ pushBackList(attr, newShortAttr(ATTR_VLAN_DESTROY, vlan));
+
+
+ return writeRequest(nga, attr);
+
+}
+
+
+
+// ----------------------------------------------------------------
+int ngadmin_getAllPVID (struct ngadmin *nga, unsigned short *ports) {
List *attr;
ListNode *ln;
+// -------------------------------------------------------------------------------
+int ngadmin_setPVID (struct ngadmin *nga, unsigned char port, unsigned short vlan) {
+
+ List *attr;
+ struct swi_attr *sa;
+ char *p;
+
+
+ if ( nga==NULL || port<1 || vlan<1 || vlan>VLAN_MAX ) {
+ return ERR_INVARG;
+ } else if ( (sa=nga->current)==NULL ) {
+ return ERR_NOTLOG;
+ } else if ( port>sa->ports ) {
+ return ERR_INVARG;
+ }
+
+
+ attr=createEmptyList();
+ p=malloc(3);
+ p[0]=port;
+ *(unsigned short*)&p[1]=htons(vlan);
+
+ pushBackList(attr, newAttr(ATTR_VLAN_PVID, 3, p));
+
+
+ return writeRequest(nga, attr);;
+
+}
+
+
+
+// ----------------------------
+int trim (char *txt, int start) {
+
+ char *p, c;
+
+
+ if ( txt==NULL ) {
+ return 0;
+ }
+
+ //for (p=txt; *p!=0; p++);
+ p=txt+start;
+ for (p--; p>=txt && ( (c=*p)==' ' || c=='\n' ); *p--=0);
+
+
+ return p-txt+1;
+
+}
+
+
+
// -------------------
int min (int a, int b) {
return a<b ? a : b ;
memset(sa, 0, sizeof(struct swi_attr));
- // FIXME: mutex lock ?
-
for (ln=l->first; ln!=NULL; ln=ln->next) {
at=ln->data;
case ATTR_PRODUCT:
len=min(at->size, PRODUCT_SIZE);
memcpy(sa->product, at->data, len);
- //trim(sa->product, len); // FIXME
+ trim(sa->product, len);
break;
case ATTR_NAME:
len=min(at->size, NAME_SIZE);
memcpy(sa->name, at->data, len);
- //trim(sa->name, len); // FIXME
+ trim(sa->name, len);
break;
case ATTR_MAC:
+
+//
+int trim (char *txt, int start);
+
//
int min (int a, int b);