5 #include <nsdp/protocol.h>
11 int ngadmin_getIGMPConf (struct ngadmin *nga, struct igmp_conf *ic)
16 struct attr_igmp_vlan *aiv;
19 if (nga == NULL || ic == NULL)
21 else if (nga->current == NULL)
24 /* ATTR_IGMP_ENABLE_VLAN
28 * apparently, read-querying these attributes at the same time causes
29 * the switch to reply garbage
30 * here we are forced to do like the official win app and send a
31 * separate request for each attribute
34 attr = createEmptyList();
35 memset(ic, 0, sizeof(struct igmp_conf));
38 pushBackList(attr, newEmptyAttr(ATTR_IGMP_ENABLE_VLAN));
39 ret = readRequest(nga, attr);
43 filterAttributes(attr, ATTR_IGMP_ENABLE_VLAN, ATTR_END);
45 if (attr->first != NULL) {
46 at = attr->first->data;
48 ic->enable = aiv->enable;
52 clearList(attr, (void(*)(void*))freeAttr);
55 pushBackList(attr, newEmptyAttr(ATTR_IGMP_BLOCK_UNK));
56 ret = readRequest(nga, attr);
60 filterAttributes(attr, ATTR_IGMP_BLOCK_UNK, ATTR_END);
62 if (attr->first != NULL) {
63 at = attr->first->data;
64 ic->block = *(char*)at->data;
67 clearList(attr, (void(*)(void*))freeAttr);
70 pushBackList(attr, newEmptyAttr(ATTR_IGMP_VALID_V3));
71 ret = readRequest(nga, attr);
75 filterAttributes(attr, ATTR_IGMP_VALID_V3, ATTR_END);
77 if (attr->first != NULL) {
78 at = attr->first->data;
79 ic->validate = *(char*)at->data;
84 destroyList(attr, (void(*)(void*))freeAttr);
91 int ngadmin_setIGMPConf (struct ngadmin *nga, const struct igmp_conf *ic)
94 struct attr_igmp_vlan *aiv;
97 if (nga == NULL || ic == NULL)
99 else if (nga->current == NULL)
103 aiv = malloc(sizeof(struct attr_igmp_vlan));
106 aiv->enable = ic->enable;
107 aiv->vlan = ic->vlan;
110 attr = createEmptyList();
111 pushBackList(attr, newAttr(ATTR_IGMP_ENABLE_VLAN, sizeof(struct attr_igmp_vlan), aiv));
112 pushBackList(attr, newByteAttr(ATTR_IGMP_BLOCK_UNK, ic->block != false));
113 pushBackList(attr, newByteAttr(ATTR_IGMP_VALID_V3, ic->validate != false));
116 return writeRequest(nga, attr);
120 int ngadmin_setNetConf (struct ngadmin *nga, const struct net_conf *nc)
125 struct net_conf nc_new;
128 if (nga == NULL || nc == NULL)
135 memcpy(&nc_new, &sa->nc, sizeof(struct net_conf));
136 if (nc->ip.s_addr != 0)
138 if (nc->netmask.s_addr != 0)
139 nc_new.netmask = nc->netmask;
140 if (nc->gw.s_addr != 0)
142 nc_new.dhcp = nc->dhcp;
144 /* gateway must be in the network range */
145 if ((nc_new.ip.s_addr & nc_new.netmask.s_addr) != (nc_new.gw.s_addr & nc_new.netmask.s_addr))
148 /* no need to send anything if old and new configurations are the same */
149 if (memcmp(&nc_new, &sa->nc, sizeof(struct net_conf)) == 0)
153 attr = createEmptyList();
155 /* Note: DHCP attribute is special, it is 2 two bytes long when sent
156 * by the switch but only 1 byte long when sent by the client
159 pushBackList(attr, newByteAttr(ATTR_DHCP, 1));
161 pushBackList(attr, newAddrAttr(ATTR_IP, nc_new.ip));
162 pushBackList(attr, newAddrAttr(ATTR_NETMASK, nc_new.netmask));
163 pushBackList(attr, newAddrAttr(ATTR_GATEWAY, nc_new.gw));
164 pushBackList(attr, newByteAttr(ATTR_DHCP, 0));
167 ret = writeRequest(nga, attr);
172 /* update local values */
173 memcpy(&sa->nc, &nc_new, sizeof(struct net_conf));