]> git.proxmox.com Git - mirror_iproute2.git/blob - tc/p_eth.c
tc: m_xt: Prevent a segfault in libipt
[mirror_iproute2.git] / tc / p_eth.c
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>
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_eth(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_ETH;
41
42 if (strcmp(*argv, "type") == 0) {
43 NEXT_ARG();
44 tkey->off = 12;
45 res = parse_cmd(&argc, &argv, 2, TU32, RU16, sel, tkey);
46 goto done;
47 }
48
49 if (strcmp(*argv, "dst") == 0) {
50 NEXT_ARG();
51 tkey->off = 0;
52 res = parse_cmd(&argc, &argv, 6, TMAC, RU32, sel, tkey);
53 goto done;
54 }
55
56 if (strcmp(*argv, "src") == 0) {
57 NEXT_ARG();
58 tkey->off = 6;
59 res = parse_cmd(&argc, &argv, 6, TMAC, RU32, sel, tkey);
60 goto done;
61 }
62
63 return -1;
64
65 done:
66 *argc_p = argc;
67 *argv_p = argv;
68 return res;
69 }
70
71 struct m_pedit_util p_pedit_eth = {
72 NULL,
73 "eth",
74 parse_eth,
75 };