xref: /aosp_15_r20/external/iproute2/tc/m_pedit.h (revision de1e4e894b0c224df933550f0afdecc354b238c4)
1*de1e4e89SAndroid Build Coastguard Worker /*
2*de1e4e89SAndroid Build Coastguard Worker  * m_pedit.h		generic packet editor actions module
3*de1e4e89SAndroid Build Coastguard Worker  *
4*de1e4e89SAndroid Build Coastguard Worker  *		This program is free software; you can distribute it and/or
5*de1e4e89SAndroid Build Coastguard Worker  *		modify it under the terms of the GNU General Public License
6*de1e4e89SAndroid Build Coastguard Worker  *		as published by the Free Software Foundation; either version
7*de1e4e89SAndroid Build Coastguard Worker  *		2 of the License, or (at your option) any later version.
8*de1e4e89SAndroid Build Coastguard Worker  *
9*de1e4e89SAndroid Build Coastguard Worker  * Authors:  J Hadi Salim ([email protected])
10*de1e4e89SAndroid Build Coastguard Worker  *
11*de1e4e89SAndroid Build Coastguard Worker  */
12*de1e4e89SAndroid Build Coastguard Worker 
13*de1e4e89SAndroid Build Coastguard Worker #ifndef _ACT_PEDIT_H_
14*de1e4e89SAndroid Build Coastguard Worker #define _ACT_PEDIT_H_ 1
15*de1e4e89SAndroid Build Coastguard Worker 
16*de1e4e89SAndroid Build Coastguard Worker #include <stdio.h>
17*de1e4e89SAndroid Build Coastguard Worker #include <stdlib.h>
18*de1e4e89SAndroid Build Coastguard Worker #include <unistd.h>
19*de1e4e89SAndroid Build Coastguard Worker #include <syslog.h>
20*de1e4e89SAndroid Build Coastguard Worker #include <fcntl.h>
21*de1e4e89SAndroid Build Coastguard Worker #include <sys/socket.h>
22*de1e4e89SAndroid Build Coastguard Worker #include <netinet/in.h>
23*de1e4e89SAndroid Build Coastguard Worker #include <arpa/inet.h>
24*de1e4e89SAndroid Build Coastguard Worker #include <string.h>
25*de1e4e89SAndroid Build Coastguard Worker #include "utils.h"
26*de1e4e89SAndroid Build Coastguard Worker #include "tc_util.h"
27*de1e4e89SAndroid Build Coastguard Worker #include <linux/tc_act/tc_pedit.h>
28*de1e4e89SAndroid Build Coastguard Worker 
29*de1e4e89SAndroid Build Coastguard Worker #define MAX_OFFS 128
30*de1e4e89SAndroid Build Coastguard Worker 
31*de1e4e89SAndroid Build Coastguard Worker #define TIPV4 1
32*de1e4e89SAndroid Build Coastguard Worker #define TIPV6 2
33*de1e4e89SAndroid Build Coastguard Worker #define TINT 3
34*de1e4e89SAndroid Build Coastguard Worker #define TU32 4
35*de1e4e89SAndroid Build Coastguard Worker #define TMAC 5
36*de1e4e89SAndroid Build Coastguard Worker 
37*de1e4e89SAndroid Build Coastguard Worker #define RU32 0xFFFFFFFF
38*de1e4e89SAndroid Build Coastguard Worker #define RU16 0xFFFF
39*de1e4e89SAndroid Build Coastguard Worker #define RU8 0xFF
40*de1e4e89SAndroid Build Coastguard Worker 
41*de1e4e89SAndroid Build Coastguard Worker #define PEDITKINDSIZ 16
42*de1e4e89SAndroid Build Coastguard Worker 
43*de1e4e89SAndroid Build Coastguard Worker struct m_pedit_key {
44*de1e4e89SAndroid Build Coastguard Worker 	__u32           mask;  /* AND */
45*de1e4e89SAndroid Build Coastguard Worker 	__u32           val;   /*XOR */
46*de1e4e89SAndroid Build Coastguard Worker 	__u32           off;  /*offset */
47*de1e4e89SAndroid Build Coastguard Worker 	__u32           at;
48*de1e4e89SAndroid Build Coastguard Worker 	__u32           offmask;
49*de1e4e89SAndroid Build Coastguard Worker 	__u32           shift;
50*de1e4e89SAndroid Build Coastguard Worker 
51*de1e4e89SAndroid Build Coastguard Worker 	enum pedit_header_type htype;
52*de1e4e89SAndroid Build Coastguard Worker 	enum pedit_cmd cmd;
53*de1e4e89SAndroid Build Coastguard Worker };
54*de1e4e89SAndroid Build Coastguard Worker 
55*de1e4e89SAndroid Build Coastguard Worker struct m_pedit_key_ex {
56*de1e4e89SAndroid Build Coastguard Worker 	enum pedit_header_type htype;
57*de1e4e89SAndroid Build Coastguard Worker 	enum pedit_cmd cmd;
58*de1e4e89SAndroid Build Coastguard Worker };
59*de1e4e89SAndroid Build Coastguard Worker 
60*de1e4e89SAndroid Build Coastguard Worker struct m_pedit_sel {
61*de1e4e89SAndroid Build Coastguard Worker 	struct tc_pedit_sel sel;
62*de1e4e89SAndroid Build Coastguard Worker 	struct tc_pedit_key keys[MAX_OFFS];
63*de1e4e89SAndroid Build Coastguard Worker 	struct m_pedit_key_ex keys_ex[MAX_OFFS];
64*de1e4e89SAndroid Build Coastguard Worker 	bool extended;
65*de1e4e89SAndroid Build Coastguard Worker };
66*de1e4e89SAndroid Build Coastguard Worker 
67*de1e4e89SAndroid Build Coastguard Worker struct m_pedit_util {
68*de1e4e89SAndroid Build Coastguard Worker 	struct m_pedit_util *next;
69*de1e4e89SAndroid Build Coastguard Worker 	char    id[PEDITKINDSIZ];
70*de1e4e89SAndroid Build Coastguard Worker 	int     (*parse_peopt)(int *argc_p, char ***argv_p,
71*de1e4e89SAndroid Build Coastguard Worker 			       struct m_pedit_sel *sel,
72*de1e4e89SAndroid Build Coastguard Worker 			       struct m_pedit_key *tkey);
73*de1e4e89SAndroid Build Coastguard Worker };
74*de1e4e89SAndroid Build Coastguard Worker 
75*de1e4e89SAndroid Build Coastguard Worker extern int pack_key(struct m_pedit_sel *sel, struct m_pedit_key *tkey);
76*de1e4e89SAndroid Build Coastguard Worker extern int pack_key32(__u32 retain, struct m_pedit_sel *sel,
77*de1e4e89SAndroid Build Coastguard Worker 		      struct m_pedit_key *tkey);
78*de1e4e89SAndroid Build Coastguard Worker extern int pack_key16(__u32 retain, struct m_pedit_sel *sel,
79*de1e4e89SAndroid Build Coastguard Worker 		      struct m_pedit_key *tkey);
80*de1e4e89SAndroid Build Coastguard Worker extern int pack_key8(__u32 retain, struct m_pedit_sel *sel,
81*de1e4e89SAndroid Build Coastguard Worker 		     struct m_pedit_key *tkey);
82*de1e4e89SAndroid Build Coastguard Worker extern int parse_val(int *argc_p, char ***argv_p, __u32 *val, int type);
83*de1e4e89SAndroid Build Coastguard Worker extern int parse_cmd(int *argc_p, char ***argv_p, __u32 len, int type,
84*de1e4e89SAndroid Build Coastguard Worker 		     __u32 retain,
85*de1e4e89SAndroid Build Coastguard Worker 		     struct m_pedit_sel *sel, struct m_pedit_key *tkey);
86*de1e4e89SAndroid Build Coastguard Worker extern int parse_offset(int *argc_p, char ***argv_p,
87*de1e4e89SAndroid Build Coastguard Worker 			struct m_pedit_sel *sel, struct m_pedit_key *tkey);
88*de1e4e89SAndroid Build Coastguard Worker int parse_pedit(struct action_util *a, int *argc_p, char ***argv_p,
89*de1e4e89SAndroid Build Coastguard Worker 		int tca_id, struct nlmsghdr *n);
90*de1e4e89SAndroid Build Coastguard Worker extern int print_pedit(struct action_util *au, FILE *f, struct rtattr *arg);
91*de1e4e89SAndroid Build Coastguard Worker extern int pedit_print_xstats(struct action_util *au, FILE *f,
92*de1e4e89SAndroid Build Coastguard Worker 			      struct rtattr *xstats);
93*de1e4e89SAndroid Build Coastguard Worker 
94*de1e4e89SAndroid Build Coastguard Worker #endif
95