~ubuntu-branches/ubuntu/precise/iproute/precise

« back to all changes in this revision

Viewing changes to ip/iplink.c

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Wirt, Andreas Henriksson, Justin B Rye, Alexander Wirt
  • Date: 2008-05-11 11:18:29 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20080511111829-rfewew7s6kiev0bh
Tags: 20080417-1
[ Andreas Henriksson ]
* New upstream release, v2.6.25 a.k.a. snapshot 20080417.
  - Initial documentation for xfrm (Partially fixes #451337)
  - Fixes manpage error caught by lintian!
* Fix typos (syntax error) in ip(8) manpage.
  - Introduced by upstream, caught by lintian yet again!
* Don't ship useless headers in iproute-dev (Closes: #467557)
* Cherry-pick "Fix bad hash calculation because of signed address" from
  upstream. (Closes: #480173)

[ Justin B Rye ]
* Update package description (Closes: #464521)

[ Alexander Wirt ]
* Fix typo in short package description.

Show diffs side-by-side

added added

removed removed

Lines of Context:
143
143
}
144
144
#endif /* ! IPLINK_IOCTL_COMPAT */
145
145
 
 
146
struct iplink_req {
 
147
        struct nlmsghdr         n;
 
148
        struct ifinfomsg        i;
 
149
        char                    buf[1024];
 
150
};
 
151
 
 
152
int iplink_parse(int argc, char **argv, struct iplink_req *req,
 
153
                char **name, char **type, char **link, char **dev)
 
154
{
 
155
        int ret, len;
 
156
        char abuf[32];
 
157
        int qlen = -1;
 
158
        int mtu = -1;
 
159
 
 
160
        ret = argc;
 
161
 
 
162
        while (argc > 0) {
 
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) {
 
170
                        NEXT_ARG();
 
171
                        *name = *argv;
 
172
                } else if (matches(*argv, "link") == 0) {
 
173
                        NEXT_ARG();
 
174
                        *link = *argv;
 
175
                } else if (matches(*argv, "address") == 0) {
 
176
                        NEXT_ARG();
 
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) {
 
181
                        NEXT_ARG();
 
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) {
 
187
                        NEXT_ARG();
 
188
                        if (qlen != -1)
 
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) {
 
194
                        NEXT_ARG();
 
195
                        if (mtu != -1)
 
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) {
 
201
                        NEXT_ARG();
 
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;
 
207
                        } else
 
208
                                return on_off("multicast");
 
209
                } else if (strcmp(*argv, "allmulticast") == 0) {
 
210
                        NEXT_ARG();
 
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;
 
216
                        } else
 
217
                                return on_off("allmulticast");
 
218
                } else if (strcmp(*argv, "promisc") == 0) {
 
219
                        NEXT_ARG();
 
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;
 
225
                        } else
 
226
                                return on_off("promisc");
 
227
                } else if (strcmp(*argv, "trailers") == 0) {
 
228
                        NEXT_ARG();
 
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;
 
234
                        } else
 
235
                                return on_off("trailers");
 
236
                } else if (strcmp(*argv, "arp") == 0) {
 
237
                        NEXT_ARG();
 
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;
 
243
                        } else
 
244
                                return on_off("noarp");
 
245
#ifdef IFF_DYNAMIC
 
246
                } else if (matches(*argv, "dynamic") == 0) {
 
247
                        NEXT_ARG();
 
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;
 
253
                        } else
 
254
                                return on_off("dynamic");
 
255
#endif
 
256
                } else if (matches(*argv, "type") == 0) {
 
257
                        NEXT_ARG();
 
258
                        *type = *argv;
 
259
                        argc--; argv++;
 
260
                        break;
 
261
                } else {
 
262
                        if (strcmp(*argv, "dev") == 0) {
 
263
                                NEXT_ARG();
 
264
                        }
 
265
                        if (*dev)
 
266
                                duparg2("dev", *argv);
 
267
                        *dev = *argv;
 
268
                }
 
269
                argc--; argv++;
 
270
        }
 
271
 
 
272
        return ret - argc;
 
273
}
 
274
 
146
275
static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
147
276
{
148
 
        int qlen = -1;
149
 
        int mtu = -1;
150
277
        int len;
151
 
        char abuf[32];
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;
157
 
        struct {
158
 
                struct nlmsghdr         n;
159
 
                struct ifinfomsg        i;
160
 
                char                    buf[1024];
161
 
        } req;
 
283
        struct iplink_req req;
 
284
        int ret;
162
285
 
163
286
        memset(&req, 0, sizeof(req));
164
287
 
167
290
        req.n.nlmsg_type = cmd;
168
291
        req.i.ifi_family = preferred_family;
169
292
 
170
 
        while (argc > 0) {
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) {
178
 
                        NEXT_ARG();
179
 
                        name = *argv;
180
 
                } else if (matches(*argv, "link") == 0) {
181
 
                        NEXT_ARG();
182
 
                        link = *argv;
183
 
                } else if (matches(*argv, "address") == 0) {
184
 
                        NEXT_ARG();
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) {
189
 
                        NEXT_ARG();
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) {
195
 
                        NEXT_ARG();
196
 
                        if (qlen != -1)
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) {
202
 
                        NEXT_ARG();
203
 
                        if (mtu != -1)
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) {
209
 
                        NEXT_ARG();
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;
215
 
                        } else
216
 
                                return on_off("multicast");
217
 
                } else if (strcmp(*argv, "allmulticast") == 0) {
218
 
                        NEXT_ARG();
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;
224
 
                        } else
225
 
                                return on_off("allmulticast");
226
 
                } else if (strcmp(*argv, "promisc") == 0) {
227
 
                        NEXT_ARG();
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;
233
 
                        } else
234
 
                                return on_off("promisc");
235
 
                } else if (strcmp(*argv, "trailers") == 0) {
236
 
                        NEXT_ARG();
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;
242
 
                        } else
243
 
                                return on_off("trailers");
244
 
                } else if (strcmp(*argv, "arp") == 0) {
245
 
                        NEXT_ARG();
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;
251
 
                        } else
252
 
                                return on_off("noarp");
253
 
#ifdef IFF_DYNAMIC
254
 
                } else if (matches(*argv, "dynamic") == 0) {
255
 
                        NEXT_ARG();
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;
261
 
                        } else
262
 
                                return on_off("dynamic");
263
 
#endif
264
 
                } else if (matches(*argv, "type") == 0) {
265
 
                        NEXT_ARG();
266
 
                        type = *argv;
267
 
                        argc--; argv++;
268
 
                        break;
269
 
                } else {
270
 
                        if (strcmp(*argv, "dev") == 0) {
271
 
                                NEXT_ARG();
272
 
                        }
273
 
                        if (dev)
274
 
                                duparg2("dev", *argv);
275
 
                        dev = *argv;
276
 
                }
277
 
                argc--; argv++;
278
 
        }
 
293
        ret = iplink_parse(argc, argv, &req, &name, &type, &link, &dev);
 
294
        if (ret < 0)
 
295
                return ret;
279
296
 
 
297
        argc -= ret;
 
298
        argv += ret;
280
299
        ll_init_map(&rth);
281
300
 
282
301
        if (type) {