]> git.proxmox.com Git - mirror_iproute2.git/blame - tc/p_ip6.c
tc: fix compiler warnings in ip6 pedit
[mirror_iproute2.git] / tc / p_ip6.c
CommitLineData
f3e1b244
AV
1/*
2 * p_ip6.c packet editor: IPV6 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>
f3e1b244
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
25static int
26parse_ip6(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
36 if (!sel->extended)
37 return -1;
38
39 tkey->htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP6;
40
41 if (strcmp(*argv, "src") == 0) {
42 NEXT_ARG();
43 tkey->off = 8;
44 res = parse_cmd(&argc, &argv, 16, TIPV6, RU32, sel, tkey);
45 goto done;
46 }
47 if (strcmp(*argv, "dst") == 0) {
48 NEXT_ARG();
49 tkey->off = 24;
50 res = parse_cmd(&argc, &argv, 16, TIPV6, RU32, sel, tkey);
51 goto done;
52 }
53 if (strcmp(*argv, "flow_lbl") == 0) {
54 NEXT_ARG();
55 tkey->off = 0;
56 res = parse_cmd(&argc, &argv, 4, TU32, 0x0007ffff, sel, tkey);
57 goto done;
58 }
59 if (strcmp(*argv, "payload_len") == 0) {
60 NEXT_ARG();
61 tkey->off = 4;
62 res = parse_cmd(&argc, &argv, 2, TU32, RU16, sel, tkey);
63 goto done;
64 }
65 if (strcmp(*argv, "nexthdr") == 0) {
66 NEXT_ARG();
67 tkey->off = 6;
68 res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
69 goto done;
70 }
71 if (strcmp(*argv, "hoplimit") == 0) {
72 NEXT_ARG();
73 tkey->off = 7;
74 res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
75 goto done;
76 }
2d9a8dc4
PM
77 if (strcmp(*argv, "traffic_class") == 0) {
78 NEXT_ARG();
79 tkey->off = 1;
80 res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
81
82 /* Shift the field by 4 bits on success. */
83 if (!res) {
84 int nkeys = sel->sel.nkeys;
2319db90 85 struct tc_pedit_key *key = &sel->keys[nkeys - 1];
2d9a8dc4
PM
86
87 key->mask = htonl(ntohl(key->mask) << 4 | 0xf);
88 key->val = htonl(ntohl(key->val) << 4);
89 }
90 goto done;
91 }
f3e1b244
AV
92
93 return -1;
94
95done:
96 *argc_p = argc;
97 *argv_p = argv;
98 return res;
99}
100
101struct m_pedit_util p_pedit_ip6 = {
2f103545 102 .id = "ip6",
946a135c 103 .parse_peopt = parse_ip6,
f3e1b244 104};