]> git.proxmox.com Git - mirror_iproute2.git/blame - tc/p_eth.c
tc/pedit: p_eth: ETH header editor
[mirror_iproute2.git] / tc / p_eth.c
CommitLineData
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>
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
26static int
27parse_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 tkey->htype = TCA_PEDIT_KEY_EX_HDR_TYPE_ETH;
38
39 if (strcmp(*argv, "type") == 0) {
40 NEXT_ARG();
41 tkey->off = 12;
42 res = parse_cmd(&argc, &argv, 2, TU32, RU16, sel, tkey);
43 goto done;
44 }
45
46 if (strcmp(*argv, "dst") == 0) {
47 NEXT_ARG();
48 tkey->off = 0;
49 res = parse_cmd(&argc, &argv, 6, TMAC, RU32, sel, tkey);
50 goto done;
51 }
52
53 if (strcmp(*argv, "src") == 0) {
54 NEXT_ARG();
55 tkey->off = 6;
56 res = parse_cmd(&argc, &argv, 6, TMAC, RU32, sel, tkey);
57 goto done;
58 }
59
60 return -1;
61
62done:
63 *argc_p = argc;
64 *argv_p = argv;
65 return res;
66}
67
68struct m_pedit_util p_pedit_eth = {
69 NULL,
70 "eth",
71 parse_eth,
72};