Debian Codegraph @

tc/p_tcp.c

raw
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * m_pedit_tcp.c packet editor: TCP header
4 *
5 * Authors: J Hadi Salim ([email protected])
6 */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <fcntl.h>
12 #include <sys/socket.h>
13 #include <netinet/in.h>
14 #include <arpa/inet.h>
15 #include <string.h>
16 #include "utils.h"
17 #include "tc_util.h"
18 #include "m_pedit.h"
19
20 static int
21 parse_tcp(int *argc_p, char ***argv_p,
22 struct m_pedit_sel *sel, struct m_pedit_key *tkey)
23 {
24 int res = -1;
25 int argc = *argc_p;
26 char **argv = *argv_p;
27
28 if (argc < 2)
29 return -1;
30
31 if (!sel->extended)
32 return -1;
33
34 tkey->htype = TCA_PEDIT_KEY_EX_HDR_TYPE_TCP;
35
36 if (strcmp(*argv, "sport") == 0) {
37 NEXT_ARG();
38 tkey->off = 0;
39 res = parse_cmd(&argc, &argv, 2, TU32, RU16, sel, tkey, 0);
40 goto done;
41 }
42
43 if (strcmp(*argv, "dport") == 0) {
44 NEXT_ARG();
45 tkey->off = 2;
46 res = parse_cmd(&argc, &argv, 2, TU32, RU16, sel, tkey, 0);
47 goto done;
48 }
49
50 if (strcmp(*argv, "flags") == 0) {
51 NEXT_ARG();
52 tkey->off = 13;
53 res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey, 0);
54 goto done;
55 }
56
57 return -1;
58
59 done:
60 *argc_p = argc;
61 *argv_p = argv;
62 return res;
63 }
64 struct m_pedit_util p_pedit_tcp = {
65 .id = "tcp",
66 .parse_peopt = parse_tcp,
67 };