]>
Commit | Line | Data |
---|---|---|
f3e1b244 AV |
1 | /* |
2 | * p_ip6.c packet editor: IPV6 header | |
3 | * | |
4 | * This program is free software; you can distribute it and/or | |
5 | * modify it under the terms of the GNU General Public License | |
6 | * as published by the Free Software Foundation; either version | |
7 | * 2 of the License, or (at your option) any later version. | |
8 | * | |
9 | * Authors: Amir Vadai <amir@vadai.me> | |
10 | * | |
11 | */ | |
12 | ||
13 | #include <stdio.h> | |
14 | #include <stdlib.h> | |
15 | #include <unistd.h> | |
16 | #include <syslog.h> | |
17 | #include <fcntl.h> | |
18 | #include <sys/socket.h> | |
19 | #include <netinet/in.h> | |
20 | #include <arpa/inet.h> | |
21 | #include <string.h> | |
22 | #include "utils.h" | |
23 | #include "tc_util.h" | |
24 | #include "m_pedit.h" | |
25 | ||
26 | static int | |
27 | parse_ip6(int *argc_p, char ***argv_p, | |
28 | struct m_pedit_sel *sel, struct m_pedit_key *tkey) | |
29 | { | |
30 | int res = -1; | |
31 | int argc = *argc_p; | |
32 | char **argv = *argv_p; | |
33 | ||
34 | if (argc < 2) | |
35 | return -1; | |
36 | ||
37 | if (!sel->extended) | |
38 | return -1; | |
39 | ||
40 | tkey->htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP6; | |
41 | ||
42 | if (strcmp(*argv, "src") == 0) { | |
43 | NEXT_ARG(); | |
44 | tkey->off = 8; | |
45 | res = parse_cmd(&argc, &argv, 16, TIPV6, RU32, sel, tkey); | |
46 | goto done; | |
47 | } | |
48 | if (strcmp(*argv, "dst") == 0) { | |
49 | NEXT_ARG(); | |
50 | tkey->off = 24; | |
51 | res = parse_cmd(&argc, &argv, 16, TIPV6, RU32, sel, tkey); | |
52 | goto done; | |
53 | } | |
54 | if (strcmp(*argv, "flow_lbl") == 0) { | |
55 | NEXT_ARG(); | |
56 | tkey->off = 0; | |
57 | res = parse_cmd(&argc, &argv, 4, TU32, 0x0007ffff, sel, tkey); | |
58 | goto done; | |
59 | } | |
60 | if (strcmp(*argv, "payload_len") == 0) { | |
61 | NEXT_ARG(); | |
62 | tkey->off = 4; | |
63 | res = parse_cmd(&argc, &argv, 2, TU32, RU16, sel, tkey); | |
64 | goto done; | |
65 | } | |
66 | if (strcmp(*argv, "nexthdr") == 0) { | |
67 | NEXT_ARG(); | |
68 | tkey->off = 6; | |
69 | res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey); | |
70 | goto done; | |
71 | } | |
72 | if (strcmp(*argv, "hoplimit") == 0) { | |
73 | NEXT_ARG(); | |
74 | tkey->off = 7; | |
75 | res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey); | |
76 | goto done; | |
77 | } | |
78 | ||
79 | return -1; | |
80 | ||
81 | done: | |
82 | *argc_p = argc; | |
83 | *argv_p = argv; | |
84 | return res; | |
85 | } | |
86 | ||
87 | struct m_pedit_util p_pedit_ip6 = { | |
88 | NULL, | |
89 | "ipv6", | |
90 | parse_ip6, | |
91 | }; |