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

« back to all changes in this revision

Viewing changes to ip/iprule.c

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Wirt, Andreas Henriksson, Ben Finney, Justin Pryzby, Daniel Silverstone, Alexander Wirt
  • Date: 2007-12-16 14:30:31 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20071216143031-cbd111kybw3o9mpv
Tags: 20071016-1
[ Andreas Henriksson ]
* New upstream release (v2.6.23 aka snapshot 071016) (Closes: #445944)
  - time2tick overflow patch applied upstream (Closes: #175462)
  - tc ematch cmp/nbyte help patch applied upstream (Closes: #438653)
  - mpath support dropped upstream (Closes: #428440, #428442)
  - new manpages included upstream (Closes: #438994)
  - linux header files updated to v2.6.23 (Closes: #409047)
* Drop patches which has been applied upstream or deprecated by
  upstream changes.
  - debian/patches/lartc applied upstream.
  - debian/patches/netbug_fix deprecated, upstream dropped netbug script.
  - debian/patches/empty_linkname.dpatch deprecated, fixed upstream.
* Add .dpatch suffix to wrr-qdisc patch to make dpatch-edit-patch work.
* Update patches to apply:
  - wrr-qdisc, moo, ip_route_usage
* Don't install removed netbug script.
* Fix corruption when using batch files with comments and broken
  lines. (cherry-picked from upstream. Closes: #398912)
* Update build-dependencies:
  - libdb4.3-dev -> libdb-dev. (Closes: #442653)
  - linux-kernel-headers -> linux-libc-dev.
* Drop debian/patches/ip_address_flush_loop.dpatch,
  instead we'll use Daniel Silverstones patch imported from Ubuntu.
* Add Homepage and Vcs-{Browser,Git} fields to debian/control.
* Remove dead/leftover code from tc/q_htb.c, include/linux/pkt_sched.h
* Remove outdated README.Debian.
* Drop our own (buggy) RTAX_INITCWND support, in favor of upstreams.
* fix dotted-quad support patch to work on big-endian.
  (upstream applied a broken patch, which we cherry-picked for #357172)

[ Ben Finney ]
* Add dh_md5sums to generate md5sums control file (Closes: #439439)

[ Justin Pryzby ]
* ss(8) manpage formatting breaks EXAMPLE (Closes: #443071)

[ Daniel Silverstone ]
* Avoid infinite loop in ip addr flush.

[ Alexander Wirt ]
* Add Andreas Henriksson to uploaders
* Bump standards version
* Support dotted-quad netmasks in iproute (Closes: #357172) (Cherry picked
  from upstream)

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
        fprintf(stderr, "ACTION := [ table TABLE_ID ]\n");
43
43
        fprintf(stderr, "          [ prohibit | reject | unreachable ]\n");
44
44
        fprintf(stderr, "          [ realms [SRCREALM/]DSTREALM ]\n");
 
45
        fprintf(stderr, "          [ goto NUMBER ]\n");
45
46
        fprintf(stderr, "TABLE_ID := [ local | main | default | NUMBER ]\n");
46
47
        exit(-1);
47
48
}
53
54
        int len = n->nlmsg_len;
54
55
        int host_len = -1;
55
56
        __u32 table;
56
 
        struct rtattr * tb[RTA_MAX+1];
 
57
        struct rtattr * tb[FRA_MAX+1];
57
58
        char abuf[256];
58
59
        SPRINT_BUF(b1);
59
60
 
64
65
        if (len < 0)
65
66
                return -1;
66
67
 
67
 
        parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
 
68
        parse_rtattr(tb, FRA_MAX, RTM_RTA(r), len);
68
69
 
69
70
        if (r->rtm_family == AF_INET)
70
71
                host_len = 32;
78
79
        if (n->nlmsg_type == RTM_DELRULE)
79
80
                fprintf(fp, "Deleted ");
80
81
 
81
 
        if (tb[RTA_PRIORITY])
82
 
                fprintf(fp, "%u:\t", *(unsigned*)RTA_DATA(tb[RTA_PRIORITY]));
 
82
        if (tb[FRA_PRIORITY])
 
83
                fprintf(fp, "%u:\t", *(unsigned*)RTA_DATA(tb[FRA_PRIORITY]));
83
84
        else
84
85
                fprintf(fp, "0:\t");
85
86
 
86
87
        if (r->rtm_flags & FIB_RULE_INVERT)
87
88
                fprintf(fp, "not ");
88
89
 
89
 
        if (tb[RTA_SRC]) {
 
90
        if (tb[FRA_SRC]) {
90
91
                if (r->rtm_src_len != host_len) {
91
92
                        fprintf(fp, "from %s/%u ", rt_addr_n2a(r->rtm_family,
92
 
                                                         RTA_PAYLOAD(tb[RTA_SRC]),
93
 
                                                         RTA_DATA(tb[RTA_SRC]),
 
93
                                                         RTA_PAYLOAD(tb[FRA_SRC]),
 
94
                                                         RTA_DATA(tb[FRA_SRC]),
94
95
                                                         abuf, sizeof(abuf)),
95
96
                                r->rtm_src_len
96
97
                                );
97
98
                } else {
98
99
                        fprintf(fp, "from %s ", format_host(r->rtm_family,
99
 
                                                       RTA_PAYLOAD(tb[RTA_SRC]),
100
 
                                                       RTA_DATA(tb[RTA_SRC]),
 
100
                                                       RTA_PAYLOAD(tb[FRA_SRC]),
 
101
                                                       RTA_DATA(tb[FRA_SRC]),
101
102
                                                       abuf, sizeof(abuf))
102
103
                                );
103
104
                }
107
108
                fprintf(fp, "from all ");
108
109
        }
109
110
 
110
 
        if (tb[RTA_DST]) {
 
111
        if (tb[FRA_DST]) {
111
112
                if (r->rtm_dst_len != host_len) {
112
113
                        fprintf(fp, "to %s/%u ", rt_addr_n2a(r->rtm_family,
113
 
                                                         RTA_PAYLOAD(tb[RTA_DST]),
114
 
                                                         RTA_DATA(tb[RTA_DST]),
 
114
                                                         RTA_PAYLOAD(tb[FRA_DST]),
 
115
                                                         RTA_DATA(tb[FRA_DST]),
115
116
                                                         abuf, sizeof(abuf)),
116
117
                                r->rtm_dst_len
117
118
                                );
118
119
                } else {
119
120
                        fprintf(fp, "to %s ", format_host(r->rtm_family,
120
 
                                                       RTA_PAYLOAD(tb[RTA_DST]),
121
 
                                                       RTA_DATA(tb[RTA_DST]),
 
121
                                                       RTA_PAYLOAD(tb[FRA_DST]),
 
122
                                                       RTA_DATA(tb[FRA_DST]),
122
123
                                                       abuf, sizeof(abuf)));
123
124
                }
124
125
        } else if (r->rtm_dst_len) {
129
130
                SPRINT_BUF(b1);
130
131
                fprintf(fp, "tos %s ", rtnl_dsfield_n2a(r->rtm_tos, b1, sizeof(b1)));
131
132
        }
132
 
        if (tb[RTA_PROTOINFO] || tb[RTA_FWMASK]) {
 
133
 
 
134
        if (tb[FRA_FWMARK] || tb[FRA_FWMASK]) {
133
135
                __u32 mark = 0, mask = 0;
134
136
 
135
 
                if (tb[RTA_PROTOINFO])
136
 
                        mark = *(__u32*)RTA_DATA(tb[RTA_PROTOINFO]);
 
137
                if (tb[FRA_FWMARK])
 
138
                        mark = *(__u32*)RTA_DATA(tb[FRA_FWMARK]);
137
139
 
138
 
                if (tb[RTA_FWMASK] &&
139
 
                    (mask = *(__u32*)RTA_DATA(tb[RTA_FWMASK])) != 0xFFFFFFFF)
 
140
                if (tb[FRA_FWMASK] &&
 
141
                    (mask = *(__u32*)RTA_DATA(tb[FRA_FWMASK])) != 0xFFFFFFFF)
140
142
                        fprintf(fp, "fwmark 0x%x/0x%x ", mark, mask);
141
143
                else
142
144
                        fprintf(fp, "fwmark 0x%x ", mark);
143
145
        }
144
146
 
145
 
        if (tb[RTA_IIF]) {
146
 
                fprintf(fp, "iif %s ", (char*)RTA_DATA(tb[RTA_IIF]));
 
147
        if (tb[FRA_IFNAME]) {
 
148
                fprintf(fp, "iif %s ", (char*)RTA_DATA(tb[FRA_IFNAME]));
 
149
                if (r->rtm_flags & FIB_RULE_DEV_DETACHED)
 
150
                        fprintf(fp, "[detached] ");
147
151
        }
148
152
 
149
153
        table = rtm_get_table(r, tb);
150
154
        if (table)
151
155
                fprintf(fp, "lookup %s ", rtnl_rttable_n2a(table, b1, sizeof(b1)));
152
156
 
153
 
        if (tb[RTA_FLOW]) {
154
 
                __u32 to = *(__u32*)RTA_DATA(tb[RTA_FLOW]);
 
157
        if (tb[FRA_FLOW]) {
 
158
                __u32 to = *(__u32*)RTA_DATA(tb[FRA_FLOW]);
155
159
                __u32 from = to>>16;
156
160
                to &= 0xFFFF;
157
161
                if (from) {
171
175
                                            abuf, sizeof(abuf)));
172
176
                } else
173
177
                        fprintf(fp, "masquerade");
174
 
        } else if (r->rtm_type != RTN_UNICAST)
 
178
        } else if (r->rtm_type == FR_ACT_GOTO) {
 
179
                fprintf(fp, "goto ");
 
180
                if (tb[FRA_GOTO])
 
181
                        fprintf(fp, "%u", *(__u32 *) RTA_DATA(tb[FRA_GOTO]));
 
182
                else
 
183
                        fprintf(fp, "none");
 
184
                if (r->rtm_flags & FIB_RULE_UNRESOLVED)
 
185
                        fprintf(fp, " [unresolved]");
 
186
        } else if (r->rtm_type == FR_ACT_NOP)
 
187
                fprintf(fp, "nop");
 
188
        else if (r->rtm_type != RTN_UNICAST)
175
189
                fprintf(fp, "%s", rtnl_rtntype_n2a(r->rtm_type, b1, sizeof(b1)));
176
190
 
177
191
        fprintf(fp, "\n");
239
253
                        NEXT_ARG();
240
254
                        get_prefix(&dst, *argv, req.r.rtm_family);
241
255
                        req.r.rtm_src_len = dst.bitlen;
242
 
                        addattr_l(&req.n, sizeof(req), RTA_SRC, &dst.data, dst.bytelen);
 
256
                        addattr_l(&req.n, sizeof(req), FRA_SRC, &dst.data, dst.bytelen);
243
257
                } else if (strcmp(*argv, "to") == 0) {
244
258
                        inet_prefix dst;
245
259
                        NEXT_ARG();
246
260
                        get_prefix(&dst, *argv, req.r.rtm_family);
247
261
                        req.r.rtm_dst_len = dst.bitlen;
248
 
                        addattr_l(&req.n, sizeof(req), RTA_DST, &dst.data, dst.bytelen);
 
262
                        addattr_l(&req.n, sizeof(req), FRA_DST, &dst.data, dst.bytelen);
249
263
                } else if (matches(*argv, "preference") == 0 ||
250
264
                           matches(*argv, "order") == 0 ||
251
265
                           matches(*argv, "priority") == 0) {
253
267
                        NEXT_ARG();
254
268
                        if (get_u32(&pref, *argv, 0))
255
269
                                invarg("preference value is invalid\n", *argv);
256
 
                        addattr32(&req.n, sizeof(req), RTA_PRIORITY, pref);
 
270
                        addattr32(&req.n, sizeof(req), FRA_PRIORITY, pref);
257
271
                } else if (strcmp(*argv, "tos") == 0) {
258
272
                        __u32 tos;
259
273
                        NEXT_ARG();
268
282
                                *slash = '\0';
269
283
                        if (get_u32(&fwmark, *argv, 0))
270
284
                                invarg("fwmark value is invalid\n", *argv);
271
 
                        addattr32(&req.n, sizeof(req), RTA_PROTOINFO, fwmark);
 
285
                        addattr32(&req.n, sizeof(req), FRA_FWMARK, fwmark);
272
286
                        if (slash) {
273
287
                                if (get_u32(&fwmask, slash+1, 0))
274
288
                                        invarg("fwmask value is invalid\n", slash+1);
275
 
                                addattr32(&req.n, sizeof(req), RTA_FWMASK, fwmask);
 
289
                                addattr32(&req.n, sizeof(req), FRA_FWMASK, fwmask);
276
290
                        }
277
291
                } else if (matches(*argv, "realms") == 0) {
278
292
                        __u32 realm;
279
293
                        NEXT_ARG();
280
294
                        if (get_rt_realms(&realm, *argv))
281
295
                                invarg("invalid realms\n", *argv);
282
 
                        addattr32(&req.n, sizeof(req), RTA_FLOW, realm);
 
296
                        addattr32(&req.n, sizeof(req), FRA_FLOW, realm);
283
297
                } else if (matches(*argv, "table") == 0 ||
284
298
                           strcmp(*argv, "lookup") == 0) {
285
299
                        __u32 tid;
290
304
                                req.r.rtm_table = tid;
291
305
                        else {
292
306
                                req.r.rtm_table = RT_TABLE_UNSPEC;
293
 
                                addattr32(&req.n, sizeof(req), RTA_TABLE, tid);
 
307
                                addattr32(&req.n, sizeof(req), FRA_TABLE, tid);
294
308
                        }
295
309
                        table_ok = 1;
296
310
                } else if (strcmp(*argv, "dev") == 0 ||
297
311
                           strcmp(*argv, "iif") == 0) {
298
312
                        NEXT_ARG();
299
 
                        addattr_l(&req.n, sizeof(req), RTA_IIF, *argv, strlen(*argv)+1);
 
313
                        addattr_l(&req.n, sizeof(req), FRA_IFNAME, *argv, strlen(*argv)+1);
300
314
                } else if (strcmp(*argv, "nat") == 0 ||
301
315
                           matches(*argv, "map-to") == 0) {
302
316
                        NEXT_ARG();
311
325
                        }
312
326
                        if (matches(*argv, "help") == 0)
313
327
                                usage();
314
 
                        if (rtnl_rtntype_a2n(&type, *argv))
 
328
                        else if (matches(*argv, "goto") == 0) {
 
329
                                __u32 target;
 
330
                                type = FR_ACT_GOTO;
 
331
                                NEXT_ARG();
 
332
                                if (get_u32(&target, *argv, 0))
 
333
                                        invarg("invalid target\n", *argv);
 
334
                                addattr32(&req.n, sizeof(req), FRA_GOTO, target);
 
335
                        } else if (matches(*argv, "nop") == 0)
 
336
                                type = FR_ACT_NOP;
 
337
                        else if (rtnl_rtntype_a2n(&type, *argv))
315
338
                                invarg("Failed to parse rule type", *argv);
316
339
                        req.r.rtm_type = type;
 
340
                        table_ok = 1;
317
341
                }
318
342
                argc--;
319
343
                argv++;
337
361
        struct rtnl_handle rth2;
338
362
        struct rtmsg *r = NLMSG_DATA(n);
339
363
        int len = n->nlmsg_len;
340
 
        struct rtattr * tb[RTA_MAX+1];
 
364
        struct rtattr * tb[FRA_MAX+1];
341
365
 
342
366
        len -= NLMSG_LENGTH(sizeof(*r));
343
367
        if (len < 0)
344
368
                return -1;
345
369
 
346
 
        parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
 
370
        parse_rtattr(tb, FRA_MAX, RTM_RTA(r), len);
347
371
 
348
 
        if (tb[RTA_PRIORITY]) {
 
372
        if (tb[FRA_PRIORITY]) {
349
373
                n->nlmsg_type = RTM_DELRULE;
350
374
                n->nlmsg_flags = NLM_F_REQUEST;
351
375