144
144
#endif /* ! IPLINK_IOCTL_COMPAT */
152
int iplink_parse(int argc, char **argv, struct iplink_req *req,
153
char **name, char **type, char **link, char **dev)
163
if (strcmp(*argv, "up") == 0) {
164
req->i.ifi_change |= IFF_UP;
165
req->i.ifi_flags |= IFF_UP;
166
} else if (strcmp(*argv, "down") == 0) {
167
req->i.ifi_change |= IFF_UP;
168
req->i.ifi_flags &= ~IFF_UP;
169
} else if (strcmp(*argv, "name") == 0) {
172
} else if (matches(*argv, "link") == 0) {
175
} else if (matches(*argv, "address") == 0) {
177
len = ll_addr_a2n(abuf, sizeof(abuf), *argv);
178
addattr_l(&req->n, sizeof(*req), IFLA_ADDRESS, abuf, len);
179
} else if (matches(*argv, "broadcast") == 0 ||
180
strcmp(*argv, "brd") == 0) {
182
len = ll_addr_a2n(abuf, sizeof(abuf), *argv);
183
addattr_l(&req->n, sizeof(*req), IFLA_BROADCAST, abuf, len);
184
} else if (matches(*argv, "txqueuelen") == 0 ||
185
strcmp(*argv, "qlen") == 0 ||
186
matches(*argv, "txqlen") == 0) {
189
duparg("txqueuelen", *argv);
190
if (get_integer(&qlen, *argv, 0))
191
invarg("Invalid \"txqueuelen\" value\n", *argv);
192
addattr_l(&req->n, sizeof(*req), IFLA_TXQLEN, &qlen, 4);
193
} else if (strcmp(*argv, "mtu") == 0) {
196
duparg("mtu", *argv);
197
if (get_integer(&mtu, *argv, 0))
198
invarg("Invalid \"mtu\" value\n", *argv);
199
addattr_l(&req->n, sizeof(*req), IFLA_MTU, &mtu, 4);
200
} else if (strcmp(*argv, "multicast") == 0) {
202
req->i.ifi_change |= IFF_MULTICAST;
203
if (strcmp(*argv, "on") == 0) {
204
req->i.ifi_flags |= IFF_MULTICAST;
205
} else if (strcmp(*argv, "off") == 0) {
206
req->i.ifi_flags &= ~IFF_MULTICAST;
208
return on_off("multicast");
209
} else if (strcmp(*argv, "allmulticast") == 0) {
211
req->i.ifi_change |= IFF_ALLMULTI;
212
if (strcmp(*argv, "on") == 0) {
213
req->i.ifi_flags |= IFF_ALLMULTI;
214
} else if (strcmp(*argv, "off") == 0) {
215
req->i.ifi_flags &= ~IFF_ALLMULTI;
217
return on_off("allmulticast");
218
} else if (strcmp(*argv, "promisc") == 0) {
220
req->i.ifi_change |= IFF_PROMISC;
221
if (strcmp(*argv, "on") == 0) {
222
req->i.ifi_flags |= IFF_PROMISC;
223
} else if (strcmp(*argv, "off") == 0) {
224
req->i.ifi_flags &= ~IFF_PROMISC;
226
return on_off("promisc");
227
} else if (strcmp(*argv, "trailers") == 0) {
229
req->i.ifi_change |= IFF_NOTRAILERS;
230
if (strcmp(*argv, "off") == 0) {
231
req->i.ifi_flags |= IFF_NOTRAILERS;
232
} else if (strcmp(*argv, "on") == 0) {
233
req->i.ifi_flags &= ~IFF_NOTRAILERS;
235
return on_off("trailers");
236
} else if (strcmp(*argv, "arp") == 0) {
238
req->i.ifi_change |= IFF_NOARP;
239
if (strcmp(*argv, "on") == 0) {
240
req->i.ifi_flags &= ~IFF_NOARP;
241
} else if (strcmp(*argv, "off") == 0) {
242
req->i.ifi_flags |= IFF_NOARP;
244
return on_off("noarp");
246
} else if (matches(*argv, "dynamic") == 0) {
248
req->i.ifi_change |= IFF_DYNAMIC;
249
if (strcmp(*argv, "on") == 0) {
250
req->i.ifi_flags |= IFF_DYNAMIC;
251
} else if (strcmp(*argv, "off") == 0) {
252
req->i.ifi_flags &= ~IFF_DYNAMIC;
254
return on_off("dynamic");
256
} else if (matches(*argv, "type") == 0) {
262
if (strcmp(*argv, "dev") == 0) {
266
duparg2("dev", *argv);
146
275
static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
152
278
char *dev = NULL;
153
279
char *name = NULL;
154
280
char *link = NULL;
155
281
char *type = NULL;
156
282
struct link_util *lu = NULL;
283
struct iplink_req req;
163
286
memset(&req, 0, sizeof(req));
167
290
req.n.nlmsg_type = cmd;
168
291
req.i.ifi_family = preferred_family;
171
if (strcmp(*argv, "up") == 0) {
172
req.i.ifi_change |= IFF_UP;
173
req.i.ifi_flags |= IFF_UP;
174
} else if (strcmp(*argv, "down") == 0) {
175
req.i.ifi_change |= IFF_UP;
176
req.i.ifi_flags &= ~IFF_UP;
177
} else if (strcmp(*argv, "name") == 0) {
180
} else if (matches(*argv, "link") == 0) {
183
} else if (matches(*argv, "address") == 0) {
185
len = ll_addr_a2n(abuf, sizeof(abuf), *argv);
186
addattr_l(&req.n, sizeof(req), IFLA_ADDRESS, abuf, len);
187
} else if (matches(*argv, "broadcast") == 0 ||
188
strcmp(*argv, "brd") == 0) {
190
len = ll_addr_a2n(abuf, sizeof(abuf), *argv);
191
addattr_l(&req.n, sizeof(req), IFLA_BROADCAST, abuf, len);
192
} else if (matches(*argv, "txqueuelen") == 0 ||
193
strcmp(*argv, "qlen") == 0 ||
194
matches(*argv, "txqlen") == 0) {
197
duparg("txqueuelen", *argv);
198
if (get_integer(&qlen, *argv, 0))
199
invarg("Invalid \"txqueuelen\" value\n", *argv);
200
addattr_l(&req.n, sizeof(req), IFLA_TXQLEN, &qlen, 4);
201
} else if (strcmp(*argv, "mtu") == 0) {
204
duparg("mtu", *argv);
205
if (get_integer(&mtu, *argv, 0))
206
invarg("Invalid \"mtu\" value\n", *argv);
207
addattr_l(&req.n, sizeof(req), IFLA_MTU, &mtu, 4);
208
} else if (strcmp(*argv, "multicast") == 0) {
210
req.i.ifi_change |= IFF_MULTICAST;
211
if (strcmp(*argv, "on") == 0) {
212
req.i.ifi_flags |= IFF_MULTICAST;
213
} else if (strcmp(*argv, "off") == 0) {
214
req.i.ifi_flags &= ~IFF_MULTICAST;
216
return on_off("multicast");
217
} else if (strcmp(*argv, "allmulticast") == 0) {
219
req.i.ifi_change |= IFF_ALLMULTI;
220
if (strcmp(*argv, "on") == 0) {
221
req.i.ifi_flags |= IFF_ALLMULTI;
222
} else if (strcmp(*argv, "off") == 0) {
223
req.i.ifi_flags &= ~IFF_ALLMULTI;
225
return on_off("allmulticast");
226
} else if (strcmp(*argv, "promisc") == 0) {
228
req.i.ifi_change |= IFF_PROMISC;
229
if (strcmp(*argv, "on") == 0) {
230
req.i.ifi_flags |= IFF_PROMISC;
231
} else if (strcmp(*argv, "off") == 0) {
232
req.i.ifi_flags &= ~IFF_PROMISC;
234
return on_off("promisc");
235
} else if (strcmp(*argv, "trailers") == 0) {
237
req.i.ifi_change |= IFF_NOTRAILERS;
238
if (strcmp(*argv, "off") == 0) {
239
req.i.ifi_flags |= IFF_NOTRAILERS;
240
} else if (strcmp(*argv, "on") == 0) {
241
req.i.ifi_flags &= ~IFF_NOTRAILERS;
243
return on_off("trailers");
244
} else if (strcmp(*argv, "arp") == 0) {
246
req.i.ifi_change |= IFF_NOARP;
247
if (strcmp(*argv, "on") == 0) {
248
req.i.ifi_flags &= ~IFF_NOARP;
249
} else if (strcmp(*argv, "off") == 0) {
250
req.i.ifi_flags |= IFF_NOARP;
252
return on_off("noarp");
254
} else if (matches(*argv, "dynamic") == 0) {
256
req.i.ifi_change |= IFF_DYNAMIC;
257
if (strcmp(*argv, "on") == 0) {
258
req.i.ifi_flags |= IFF_DYNAMIC;
259
} else if (strcmp(*argv, "off") == 0) {
260
req.i.ifi_flags &= ~IFF_DYNAMIC;
262
return on_off("dynamic");
264
} else if (matches(*argv, "type") == 0) {
270
if (strcmp(*argv, "dev") == 0) {
274
duparg2("dev", *argv);
293
ret = iplink_parse(argc, argv, &req, &name, &type, &link, &dev);
280
299
ll_init_map(&rth);