• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * m_pedit.h		generic packet editor actions module
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 #ifndef _ACT_PEDIT_H_
14 #define _ACT_PEDIT_H_ 1
15 
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <unistd.h>
19 #include <syslog.h>
20 #include <fcntl.h>
21 #include <sys/socket.h>
22 #include <netinet/in.h>
23 #include <arpa/inet.h>
24 #include <string.h>
25 #include "utils.h"
26 #include "tc_util.h"
27 #include <linux/tc_act/tc_pedit.h>
28 
29 #define MAX_OFFS 128
30 
31 #define TIPV4 1
32 #define TIPV6 2
33 #define TINT 3
34 #define TU32 4
35 #define TMAC 5
36 
37 #define RU32 0xFFFFFFFF
38 #define RU16 0xFFFF
39 #define RU8 0xFF
40 
41 #define PEDITKINDSIZ 16
42 
43 struct m_pedit_key {
44 	__u32           mask;  /* AND */
45 	__u32           val;   /*XOR */
46 	__u32           off;  /*offset */
47 	__u32           at;
48 	__u32           offmask;
49 	__u32           shift;
50 
51 	enum pedit_header_type htype;
52 	enum pedit_cmd cmd;
53 };
54 
55 struct m_pedit_key_ex {
56 	enum pedit_header_type htype;
57 	enum pedit_cmd cmd;
58 };
59 
60 struct m_pedit_sel {
61 	struct tc_pedit_sel sel;
62 	struct tc_pedit_key keys[MAX_OFFS];
63 	struct m_pedit_key_ex keys_ex[MAX_OFFS];
64 	bool extended;
65 };
66 
67 struct m_pedit_util {
68 	struct m_pedit_util *next;
69 	char    id[PEDITKINDSIZ];
70 	int     (*parse_peopt)(int *argc_p, char ***argv_p,
71 			       struct m_pedit_sel *sel,
72 			       struct m_pedit_key *tkey);
73 };
74 
75 extern int pack_key(struct m_pedit_sel *sel, struct m_pedit_key *tkey);
76 extern int pack_key32(__u32 retain, struct m_pedit_sel *sel,
77 		      struct m_pedit_key *tkey);
78 extern int pack_key16(__u32 retain, struct m_pedit_sel *sel,
79 		      struct m_pedit_key *tkey);
80 extern int pack_key8(__u32 retain, struct m_pedit_sel *sel,
81 		     struct m_pedit_key *tkey);
82 extern int parse_val(int *argc_p, char ***argv_p, __u32 *val, int type);
83 extern int parse_cmd(int *argc_p, char ***argv_p, __u32 len, int type,
84 		     __u32 retain,
85 		     struct m_pedit_sel *sel, struct m_pedit_key *tkey);
86 extern int parse_offset(int *argc_p, char ***argv_p,
87 			struct m_pedit_sel *sel, struct m_pedit_key *tkey);
88 int parse_pedit(struct action_util *a, int *argc_p, char ***argv_p,
89 		int tca_id, struct nlmsghdr *n);
90 extern int print_pedit(struct action_util *au, FILE *f, struct rtattr *arg);
91 extern int pedit_print_xstats(struct action_util *au, FILE *f,
92 			      struct rtattr *xstats);
93 
94 #endif
95