]> git.proxmox.com Git - mirror_iproute2.git/blame - tc/p_ip.c
bridge: fdb: add support for src_vni option
[mirror_iproute2.git] / tc / p_ip.c
CommitLineData
7e7c7372 1/*
f3e1b244 2 * p_ip.c packet editor: IPV4 header
7e7c7372 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 *
ae665a52
SH
9 * Authors: J Hadi Salim (hadi@cyberus.ca)
10 *
7e7c7372 11 */
12
13#include <stdio.h>
14#include <stdlib.h>
15#include <unistd.h>
7e7c7372 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
952f89de 26parse_ip(int *argc_p, char ***argv_p,
7c71a40c 27 struct m_pedit_sel *sel, struct m_pedit_key *tkey)
7e7c7372 28{
29 int res = -1;
30 int argc = *argc_p;
31 char **argv = *argv_p;
32
33 if (argc < 2)
34 return -1;
35
7c71a40c
AV
36 tkey->htype = sel->extended ?
37 TCA_PEDIT_KEY_EX_HDR_TYPE_IP4 :
38 TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK;
39
7e7c7372 40 if (strcmp(*argv, "src") == 0) {
41 NEXT_ARG();
42 tkey->off = 12;
32a121cb 43 res = parse_cmd(&argc, &argv, 4, TIPV4, RU32, sel, tkey);
7e7c7372 44 goto done;
45 }
46 if (strcmp(*argv, "dst") == 0) {
47 NEXT_ARG();
48 tkey->off = 16;
32a121cb 49 res = parse_cmd(&argc, &argv, 4, TIPV4, RU32, sel, tkey);
7e7c7372 50 goto done;
51 }
52 /* jamal - look at these and make them either old or new
53 ** scheme given diffserv
f5a398bf 54 ** don't forget the CE bit
7e7c7372 55 */
56 if (strcmp(*argv, "tos") == 0 || matches(*argv, "dsfield") == 0) {
57 NEXT_ARG();
58 tkey->off = 1;
952f89de 59 res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
7e7c7372 60 goto done;
61 }
62 if (strcmp(*argv, "ihl") == 0) {
63 NEXT_ARG();
64 tkey->off = 0;
32a121cb 65 res = parse_cmd(&argc, &argv, 1, TU32, 0x0f, sel, tkey);
7e7c7372 66 goto done;
67 }
8d193d96
AV
68 if (strcmp(*argv, "ttl") == 0) {
69 NEXT_ARG();
70 tkey->off = 8;
71 res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
72 goto done;
73 }
7e7c7372 74 if (strcmp(*argv, "protocol") == 0) {
75 NEXT_ARG();
76 tkey->off = 9;
32a121cb 77 res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
7e7c7372 78 goto done;
79 }
80 /* jamal - fix this */
81 if (matches(*argv, "precedence") == 0) {
82 NEXT_ARG();
83 tkey->off = 1;
32a121cb 84 res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
7e7c7372 85 goto done;
86 }
87 /* jamal - validate this at some point */
88 if (strcmp(*argv, "nofrag") == 0) {
89 NEXT_ARG();
90 tkey->off = 6;
32a121cb 91 res = parse_cmd(&argc, &argv, 1, TU32, 0x3F, sel, tkey);
7e7c7372 92 goto done;
93 }
94 /* jamal - validate this at some point */
95 if (strcmp(*argv, "firstfrag") == 0) {
96 NEXT_ARG();
97 tkey->off = 6;
32a121cb 98 res = parse_cmd(&argc, &argv, 1, TU32, 0x1F, sel, tkey);
7e7c7372 99 goto done;
100 }
101 if (strcmp(*argv, "ce") == 0) {
102 NEXT_ARG();
103 tkey->off = 6;
32a121cb 104 res = parse_cmd(&argc, &argv, 1, TU32, 0x80, sel, tkey);
7e7c7372 105 goto done;
106 }
107 if (strcmp(*argv, "df") == 0) {
108 NEXT_ARG();
109 tkey->off = 6;
32a121cb 110 res = parse_cmd(&argc, &argv, 1, TU32, 0x40, sel, tkey);
7e7c7372 111 goto done;
112 }
113 if (strcmp(*argv, "mf") == 0) {
114 NEXT_ARG();
115 tkey->off = 6;
32a121cb 116 res = parse_cmd(&argc, &argv, 1, TU32, 0x20, sel, tkey);
7e7c7372 117 goto done;
118 }
7c71a40c
AV
119
120 if (sel->extended)
121 return -1; /* fields located outside IP header should be
122 * addressed using the relevant header type in
123 * extended pedit kABI
124 */
125
7e7c7372 126 if (strcmp(*argv, "dport") == 0) {
127 NEXT_ARG();
128 tkey->off = 22;
32a121cb 129 res = parse_cmd(&argc, &argv, 2, TU32, RU16, sel, tkey);
7e7c7372 130 goto done;
131 }
132 if (strcmp(*argv, "sport") == 0) {
133 NEXT_ARG();
134 tkey->off = 20;
32a121cb 135 res = parse_cmd(&argc, &argv, 2, TU32, RU16, sel, tkey);
7e7c7372 136 goto done;
137 }
138 if (strcmp(*argv, "icmp_type") == 0) {
139 NEXT_ARG();
140 tkey->off = 20;
32a121cb 141 res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
7e7c7372 142 goto done;
143 }
144 if (strcmp(*argv, "icmp_code") == 0) {
145 NEXT_ARG();
146 tkey->off = 20;
32a121cb 147 res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
7e7c7372 148 goto done;
149 }
150 return -1;
151
32a121cb 152done:
7e7c7372 153 *argc_p = argc;
154 *argv_p = argv;
155 return res;
156}
157
7e7c7372 158struct m_pedit_util p_pedit_ip = {
946a135c
SH
159 .id = "ip",
160 .parse_peopt = parse_ip,
7e7c7372 161};