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)
17 #include <sys/socket.h>
18 #include <netinet/in.h>
19 #include <arpa/inet.h>
26 parse_ip(int *argc_p, char ***argv_p,
27 struct m_pedit_sel *sel, struct m_pedit_key *tkey)
31 char **argv = *argv_p;
36 tkey->htype = sel->extended ?
37 TCA_PEDIT_KEY_EX_HDR_TYPE_IP4 :
38 TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK;
40 if (strcmp(*argv, "src") == 0) {
43 res = parse_cmd(&argc, &argv, 4, TIPV4, RU32, sel, tkey);
46 if (strcmp(*argv, "dst") == 0) {
49 res = parse_cmd(&argc, &argv, 4, TIPV4, RU32, sel, tkey);
52 /* jamal - look at these and make them either old or new
53 ** scheme given diffserv
54 ** don't forget the CE bit
56 if (strcmp(*argv, "tos") == 0 || matches(*argv, "dsfield") == 0) {
59 res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
62 if (strcmp(*argv, "ihl") == 0) {
65 res = parse_cmd(&argc, &argv, 1, TU32, 0x0f, sel, tkey);
68 if (strcmp(*argv, "ttl") == 0) {
71 res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
74 if (strcmp(*argv, "protocol") == 0) {
77 res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
80 /* jamal - fix this */
81 if (matches(*argv, "precedence") == 0) {
84 res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
87 /* jamal - validate this at some point */
88 if (strcmp(*argv, "nofrag") == 0) {
91 res = parse_cmd(&argc, &argv, 1, TU32, 0x3F, sel, tkey);
94 /* jamal - validate this at some point */
95 if (strcmp(*argv, "firstfrag") == 0) {
98 res = parse_cmd(&argc, &argv, 1, TU32, 0x1F, sel, tkey);
101 if (strcmp(*argv, "ce") == 0) {
104 res = parse_cmd(&argc, &argv, 1, TU32, 0x80, sel, tkey);
107 if (strcmp(*argv, "df") == 0) {
110 res = parse_cmd(&argc, &argv, 1, TU32, 0x40, sel, tkey);
113 if (strcmp(*argv, "mf") == 0) {
116 res = parse_cmd(&argc, &argv, 1, TU32, 0x20, sel, tkey);
121 return -1; /* fields located outside IP header should be
122 * addressed using the relevant header type in
123 * extended pedit kABI
126 if (strcmp(*argv, "dport") == 0) {
129 res = parse_cmd(&argc, &argv, 2, TU32, RU16, sel, tkey);
132 if (strcmp(*argv, "sport") == 0) {
135 res = parse_cmd(&argc, &argv, 2, TU32, RU16, sel, tkey);
138 if (strcmp(*argv, "icmp_type") == 0) {
141 res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
144 if (strcmp(*argv, "icmp_code") == 0) {
147 res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
158 struct m_pedit_util p_pedit_ip = {
160 .parse_peopt = parse_ip,