]>
Commit | Line | Data |
---|---|---|
3cd5149e AV |
1 | /* |
2 | * m_pedit_eth.c packet editor: ETH 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> | |
3cd5149e AV |
16 | #include <fcntl.h> |
17 | #include <sys/socket.h> | |
18 | #include <netinet/in.h> | |
19 | #include <arpa/inet.h> | |
20 | #include <string.h> | |
21 | #include "utils.h" | |
22 | #include "tc_util.h" | |
23 | #include "m_pedit.h" | |
24 | ||
25 | static int | |
26 | parse_eth(int *argc_p, char ***argv_p, | |
27 | struct m_pedit_sel *sel, struct m_pedit_key *tkey) | |
28 | { | |
29 | int res = -1; | |
30 | int argc = *argc_p; | |
31 | char **argv = *argv_p; | |
32 | ||
33 | if (argc < 2) | |
34 | return -1; | |
35 | ||
a13426fe AV |
36 | if (!sel->extended) |
37 | return -1; | |
38 | ||
3cd5149e AV |
39 | tkey->htype = TCA_PEDIT_KEY_EX_HDR_TYPE_ETH; |
40 | ||
41 | if (strcmp(*argv, "type") == 0) { | |
42 | NEXT_ARG(); | |
43 | tkey->off = 12; | |
44 | res = parse_cmd(&argc, &argv, 2, TU32, RU16, sel, tkey); | |
45 | goto done; | |
46 | } | |
47 | ||
48 | if (strcmp(*argv, "dst") == 0) { | |
49 | NEXT_ARG(); | |
50 | tkey->off = 0; | |
51 | res = parse_cmd(&argc, &argv, 6, TMAC, RU32, sel, tkey); | |
52 | goto done; | |
53 | } | |
54 | ||
55 | if (strcmp(*argv, "src") == 0) { | |
56 | NEXT_ARG(); | |
57 | tkey->off = 6; | |
58 | res = parse_cmd(&argc, &argv, 6, TMAC, RU32, sel, tkey); | |
59 | goto done; | |
60 | } | |
61 | ||
62 | return -1; | |
63 | ||
64 | done: | |
65 | *argc_p = argc; | |
66 | *argv_p = argv; | |
67 | return res; | |
68 | } | |
69 | ||
70 | struct m_pedit_util p_pedit_eth = { | |
946a135c SH |
71 | .id = "eth", |
72 | .parse_peopt = parse_eth, | |
3cd5149e | 73 | }; |