2 * p_ip.c packet editor: IPV4 header
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.
9 * Authors: J Hadi Salim (hadi@cyberus.ca)
18 #include <sys/socket.h>
19 #include <netinet/in.h>
20 #include <arpa/inet.h>
27 parse_ip(int *argc_p
, char ***argv_p
,
28 struct m_pedit_sel
*sel
, struct m_pedit_key
*tkey
)
32 char **argv
= *argv_p
;
37 tkey
->htype
= sel
->extended
?
38 TCA_PEDIT_KEY_EX_HDR_TYPE_IP4
:
39 TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK
;
41 if (strcmp(*argv
, "src") == 0) {
44 res
= parse_cmd(&argc
, &argv
, 4, TIPV4
, RU32
, sel
, tkey
);
47 if (strcmp(*argv
, "dst") == 0) {
50 res
= parse_cmd(&argc
, &argv
, 4, TIPV4
, RU32
, sel
, tkey
);
53 /* jamal - look at these and make them either old or new
54 ** scheme given diffserv
55 ** dont forget the CE bit
57 if (strcmp(*argv
, "tos") == 0 || matches(*argv
, "dsfield") == 0) {
60 res
= parse_cmd(&argc
, &argv
, 1, TU32
, RU8
, sel
, tkey
);
63 if (strcmp(*argv
, "ihl") == 0) {
66 res
= parse_cmd(&argc
, &argv
, 1, TU32
, 0x0f, sel
, tkey
);
69 if (strcmp(*argv
, "ttl") == 0) {
72 res
= parse_cmd(&argc
, &argv
, 1, TU32
, RU8
, sel
, tkey
);
75 if (strcmp(*argv
, "protocol") == 0) {
78 res
= parse_cmd(&argc
, &argv
, 1, TU32
, RU8
, sel
, tkey
);
81 /* jamal - fix this */
82 if (matches(*argv
, "precedence") == 0) {
85 res
= parse_cmd(&argc
, &argv
, 1, TU32
, RU8
, sel
, tkey
);
88 /* jamal - validate this at some point */
89 if (strcmp(*argv
, "nofrag") == 0) {
92 res
= parse_cmd(&argc
, &argv
, 1, TU32
, 0x3F, sel
, tkey
);
95 /* jamal - validate this at some point */
96 if (strcmp(*argv
, "firstfrag") == 0) {
99 res
= parse_cmd(&argc
, &argv
, 1, TU32
, 0x1F, sel
, tkey
);
102 if (strcmp(*argv
, "ce") == 0) {
105 res
= parse_cmd(&argc
, &argv
, 1, TU32
, 0x80, sel
, tkey
);
108 if (strcmp(*argv
, "df") == 0) {
111 res
= parse_cmd(&argc
, &argv
, 1, TU32
, 0x40, sel
, tkey
);
114 if (strcmp(*argv
, "mf") == 0) {
117 res
= parse_cmd(&argc
, &argv
, 1, TU32
, 0x20, sel
, tkey
);
122 return -1; /* fields located outside IP header should be
123 * addressed using the relevant header type in
124 * extended pedit kABI
127 if (strcmp(*argv
, "dport") == 0) {
130 res
= parse_cmd(&argc
, &argv
, 2, TU32
, RU16
, sel
, tkey
);
133 if (strcmp(*argv
, "sport") == 0) {
136 res
= parse_cmd(&argc
, &argv
, 2, TU32
, RU16
, sel
, tkey
);
139 if (strcmp(*argv
, "icmp_type") == 0) {
142 res
= parse_cmd(&argc
, &argv
, 1, TU32
, RU8
, sel
, tkey
);
145 if (strcmp(*argv
, "icmp_code") == 0) {
148 res
= parse_cmd(&argc
, &argv
, 1, TU32
, RU8
, sel
, tkey
);
159 struct m_pedit_util p_pedit_ip
= {