]> git.proxmox.com Git - mirror_iproute2.git/blob - tc/p_udp.c
pedit: Check for extended capability in protocol parser
[mirror_iproute2.git] / tc / p_udp.c
1 /*
2 * m_pedit_udp.c packet editor: UDP 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: J Hadi Salim (hadi@cyberus.ca)
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_udp(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_UDP;
41
42 if (strcmp(*argv, "sport") == 0) {
43 NEXT_ARG();
44 tkey->off = 0;
45 res = parse_cmd(&argc, &argv, 2, TU32, RU16, sel, tkey);
46 goto done;
47 }
48
49 if (strcmp(*argv, "dport") == 0) {
50 NEXT_ARG();
51 tkey->off = 2;
52 res = parse_cmd(&argc, &argv, 2, TU32, RU16, sel, tkey);
53 goto done;
54 }
55
56 return -1;
57
58 done:
59 *argc_p = argc;
60 *argv_p = argv;
61 return res;
62 }
63
64 struct m_pedit_util p_pedit_udp = {
65 NULL,
66 "udp",
67 parse_udp,
68 };