pkt_cls.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. #ifndef __LINUX_PKT_CLS_H
  2. #define __LINUX_PKT_CLS_H
  3. #include <linux/types.h>
  4. #include <linux/pkt_sched.h>
  5. #ifdef __KERNEL__
  6. /* I think i could have done better macros ; for now this is stolen from
  7. * some arch/mips code - jhs
  8. */
  9. #define _TC_MAKE32(x) ((x))
  10. #define _TC_MAKEMASK1(n) (_TC_MAKE32(1) << _TC_MAKE32(n))
  11. #define _TC_MAKEMASK(v,n) (_TC_MAKE32((_TC_MAKE32(1)<<(v))-1) << _TC_MAKE32(n))
  12. #define _TC_MAKEVALUE(v,n) (_TC_MAKE32(v) << _TC_MAKE32(n))
  13. #define _TC_GETVALUE(v,n,m) ((_TC_MAKE32(v) & _TC_MAKE32(m)) >> _TC_MAKE32(n))
  14. /* verdict bit breakdown
  15. *
  16. bit 0: when set -> this packet has been munged already
  17. bit 1: when set -> It is ok to munge this packet
  18. bit 2,3,4,5: Reclassify counter - sort of reverse TTL - if exceeded
  19. assume loop
  20. bit 6,7: Where this packet was last seen
  21. 0: Above the transmit example at the socket level
  22. 1: on the Ingress
  23. 2: on the Egress
  24. bit 8: when set --> Request not to classify on ingress.
  25. bits 9,10,11: redirect counter - redirect TTL. Loop avoidance
  26. *
  27. * */
  28. #define S_TC_FROM _TC_MAKE32(6)
  29. #define M_TC_FROM _TC_MAKEMASK(2,S_TC_FROM)
  30. #define G_TC_FROM(x) _TC_GETVALUE(x,S_TC_FROM,M_TC_FROM)
  31. #define V_TC_FROM(x) _TC_MAKEVALUE(x,S_TC_FROM)
  32. #define SET_TC_FROM(v,n) ((V_TC_FROM(n)) | (v & ~M_TC_FROM))
  33. #define AT_STACK 0x0
  34. #define AT_INGRESS 0x1
  35. #define AT_EGRESS 0x2
  36. #define TC_NCLS _TC_MAKEMASK1(8)
  37. #define SET_TC_NCLS(v) ( TC_NCLS | (v & ~TC_NCLS))
  38. #define CLR_TC_NCLS(v) ( v & ~TC_NCLS)
  39. #define S_TC_AT _TC_MAKE32(12)
  40. #define M_TC_AT _TC_MAKEMASK(2,S_TC_AT)
  41. #define G_TC_AT(x) _TC_GETVALUE(x,S_TC_AT,M_TC_AT)
  42. #define V_TC_AT(x) _TC_MAKEVALUE(x,S_TC_AT)
  43. #define SET_TC_AT(v,n) ((V_TC_AT(n)) | (v & ~M_TC_AT))
  44. #define MAX_REC_LOOP 4
  45. #define MAX_RED_LOOP 4
  46. #endif
  47. /* Action attributes */
  48. enum {
  49. TCA_ACT_UNSPEC,
  50. TCA_ACT_KIND,
  51. TCA_ACT_OPTIONS,
  52. TCA_ACT_INDEX,
  53. TCA_ACT_STATS,
  54. __TCA_ACT_MAX
  55. };
  56. #define TCA_ACT_MAX __TCA_ACT_MAX
  57. #define TCA_OLD_COMPAT (TCA_ACT_MAX+1)
  58. #define TCA_ACT_MAX_PRIO 32
  59. #define TCA_ACT_BIND 1
  60. #define TCA_ACT_NOBIND 0
  61. #define TCA_ACT_UNBIND 1
  62. #define TCA_ACT_NOUNBIND 0
  63. #define TCA_ACT_REPLACE 1
  64. #define TCA_ACT_NOREPLACE 0
  65. #define TC_ACT_UNSPEC (-1)
  66. #define TC_ACT_OK 0
  67. #define TC_ACT_RECLASSIFY 1
  68. #define TC_ACT_SHOT 2
  69. #define TC_ACT_PIPE 3
  70. #define TC_ACT_STOLEN 4
  71. #define TC_ACT_QUEUED 5
  72. #define TC_ACT_REPEAT 6
  73. #define TC_ACT_REDIRECT 7
  74. #define TC_ACT_JUMP 0x10000000
  75. /* Action type identifiers*/
  76. enum {
  77. TCA_ID_UNSPEC=0,
  78. TCA_ID_POLICE=1,
  79. /* other actions go here */
  80. __TCA_ID_MAX=255
  81. };
  82. #define TCA_ID_MAX __TCA_ID_MAX
  83. struct tc_police {
  84. __u32 index;
  85. int action;
  86. #define TC_POLICE_UNSPEC TC_ACT_UNSPEC
  87. #define TC_POLICE_OK TC_ACT_OK
  88. #define TC_POLICE_RECLASSIFY TC_ACT_RECLASSIFY
  89. #define TC_POLICE_SHOT TC_ACT_SHOT
  90. #define TC_POLICE_PIPE TC_ACT_PIPE
  91. __u32 limit;
  92. __u32 burst;
  93. __u32 mtu;
  94. struct tc_ratespec rate;
  95. struct tc_ratespec peakrate;
  96. int refcnt;
  97. int bindcnt;
  98. __u32 capab;
  99. };
  100. struct tcf_t {
  101. __u64 install;
  102. __u64 lastuse;
  103. __u64 expires;
  104. };
  105. struct tc_cnt {
  106. int refcnt;
  107. int bindcnt;
  108. };
  109. #define tc_gen \
  110. __u32 index; \
  111. __u32 capab; \
  112. int action; \
  113. int refcnt; \
  114. int bindcnt
  115. enum {
  116. TCA_POLICE_UNSPEC,
  117. TCA_POLICE_TBF,
  118. TCA_POLICE_RATE,
  119. TCA_POLICE_PEAKRATE,
  120. TCA_POLICE_AVRATE,
  121. TCA_POLICE_RESULT,
  122. __TCA_POLICE_MAX
  123. #define TCA_POLICE_RESULT TCA_POLICE_RESULT
  124. };
  125. #define TCA_POLICE_MAX (__TCA_POLICE_MAX - 1)
  126. /* U32 filters */
  127. #define TC_U32_HTID(h) ((h)&0xFFF00000)
  128. #define TC_U32_USERHTID(h) (TC_U32_HTID(h)>>20)
  129. #define TC_U32_HASH(h) (((h)>>12)&0xFF)
  130. #define TC_U32_NODE(h) ((h)&0xFFF)
  131. #define TC_U32_KEY(h) ((h)&0xFFFFF)
  132. #define TC_U32_UNSPEC 0
  133. #define TC_U32_ROOT (0xFFF00000)
  134. enum {
  135. TCA_U32_UNSPEC,
  136. TCA_U32_CLASSID,
  137. TCA_U32_HASH,
  138. TCA_U32_LINK,
  139. TCA_U32_DIVISOR,
  140. TCA_U32_SEL,
  141. TCA_U32_POLICE,
  142. TCA_U32_ACT,
  143. TCA_U32_INDEV,
  144. TCA_U32_PCNT,
  145. TCA_U32_MARK,
  146. __TCA_U32_MAX
  147. };
  148. #define TCA_U32_MAX (__TCA_U32_MAX - 1)
  149. struct tc_u32_key {
  150. __be32 mask;
  151. __be32 val;
  152. int off;
  153. int offmask;
  154. };
  155. struct tc_u32_sel {
  156. unsigned char flags;
  157. unsigned char offshift;
  158. unsigned char nkeys;
  159. __be16 offmask;
  160. __u16 off;
  161. short offoff;
  162. short hoff;
  163. __be32 hmask;
  164. struct tc_u32_key keys[0];
  165. };
  166. struct tc_u32_mark {
  167. __u32 val;
  168. __u32 mask;
  169. __u32 success;
  170. };
  171. struct tc_u32_pcnt {
  172. __u64 rcnt;
  173. __u64 rhit;
  174. __u64 kcnts[0];
  175. };
  176. /* Flags */
  177. #define TC_U32_TERMINAL 1
  178. #define TC_U32_OFFSET 2
  179. #define TC_U32_VAROFFSET 4
  180. #define TC_U32_EAT 8
  181. #define TC_U32_MAXDEPTH 8
  182. /* RSVP filter */
  183. enum {
  184. TCA_RSVP_UNSPEC,
  185. TCA_RSVP_CLASSID,
  186. TCA_RSVP_DST,
  187. TCA_RSVP_SRC,
  188. TCA_RSVP_PINFO,
  189. TCA_RSVP_POLICE,
  190. TCA_RSVP_ACT,
  191. __TCA_RSVP_MAX
  192. };
  193. #define TCA_RSVP_MAX (__TCA_RSVP_MAX - 1 )
  194. struct tc_rsvp_gpi {
  195. __u32 key;
  196. __u32 mask;
  197. int offset;
  198. };
  199. struct tc_rsvp_pinfo {
  200. struct tc_rsvp_gpi dpi;
  201. struct tc_rsvp_gpi spi;
  202. __u8 protocol;
  203. __u8 tunnelid;
  204. __u8 tunnelhdr;
  205. __u8 pad;
  206. };
  207. /* ROUTE filter */
  208. enum {
  209. TCA_ROUTE4_UNSPEC,
  210. TCA_ROUTE4_CLASSID,
  211. TCA_ROUTE4_TO,
  212. TCA_ROUTE4_FROM,
  213. TCA_ROUTE4_IIF,
  214. TCA_ROUTE4_POLICE,
  215. TCA_ROUTE4_ACT,
  216. __TCA_ROUTE4_MAX
  217. };
  218. #define TCA_ROUTE4_MAX (__TCA_ROUTE4_MAX - 1)
  219. /* FW filter */
  220. enum {
  221. TCA_FW_UNSPEC,
  222. TCA_FW_CLASSID,
  223. TCA_FW_POLICE,
  224. TCA_FW_INDEV, /* used by CONFIG_NET_CLS_IND */
  225. TCA_FW_ACT, /* used by CONFIG_NET_CLS_ACT */
  226. TCA_FW_MASK,
  227. __TCA_FW_MAX
  228. };
  229. #define TCA_FW_MAX (__TCA_FW_MAX - 1)
  230. /* TC index filter */
  231. enum {
  232. TCA_TCINDEX_UNSPEC,
  233. TCA_TCINDEX_HASH,
  234. TCA_TCINDEX_MASK,
  235. TCA_TCINDEX_SHIFT,
  236. TCA_TCINDEX_FALL_THROUGH,
  237. TCA_TCINDEX_CLASSID,
  238. TCA_TCINDEX_POLICE,
  239. TCA_TCINDEX_ACT,
  240. __TCA_TCINDEX_MAX
  241. };
  242. #define TCA_TCINDEX_MAX (__TCA_TCINDEX_MAX - 1)
  243. /* Flow filter */
  244. enum {
  245. FLOW_KEY_SRC,
  246. FLOW_KEY_DST,
  247. FLOW_KEY_PROTO,
  248. FLOW_KEY_PROTO_SRC,
  249. FLOW_KEY_PROTO_DST,
  250. FLOW_KEY_IIF,
  251. FLOW_KEY_PRIORITY,
  252. FLOW_KEY_MARK,
  253. FLOW_KEY_NFCT,
  254. FLOW_KEY_NFCT_SRC,
  255. FLOW_KEY_NFCT_DST,
  256. FLOW_KEY_NFCT_PROTO_SRC,
  257. FLOW_KEY_NFCT_PROTO_DST,
  258. FLOW_KEY_RTCLASSID,
  259. FLOW_KEY_SKUID,
  260. FLOW_KEY_SKGID,
  261. FLOW_KEY_VLAN_TAG,
  262. FLOW_KEY_RXHASH,
  263. __FLOW_KEY_MAX,
  264. };
  265. #define FLOW_KEY_MAX (__FLOW_KEY_MAX - 1)
  266. enum {
  267. FLOW_MODE_MAP,
  268. FLOW_MODE_HASH,
  269. };
  270. enum {
  271. TCA_FLOW_UNSPEC,
  272. TCA_FLOW_KEYS,
  273. TCA_FLOW_MODE,
  274. TCA_FLOW_BASECLASS,
  275. TCA_FLOW_RSHIFT,
  276. TCA_FLOW_ADDEND,
  277. TCA_FLOW_MASK,
  278. TCA_FLOW_XOR,
  279. TCA_FLOW_DIVISOR,
  280. TCA_FLOW_ACT,
  281. TCA_FLOW_POLICE,
  282. TCA_FLOW_EMATCHES,
  283. TCA_FLOW_PERTURB,
  284. __TCA_FLOW_MAX
  285. };
  286. #define TCA_FLOW_MAX (__TCA_FLOW_MAX - 1)
  287. /* Basic filter */
  288. enum {
  289. TCA_BASIC_UNSPEC,
  290. TCA_BASIC_CLASSID,
  291. TCA_BASIC_EMATCHES,
  292. TCA_BASIC_ACT,
  293. TCA_BASIC_POLICE,
  294. __TCA_BASIC_MAX
  295. };
  296. #define TCA_BASIC_MAX (__TCA_BASIC_MAX - 1)
  297. /* Cgroup classifier */
  298. enum {
  299. TCA_CGROUP_UNSPEC,
  300. TCA_CGROUP_ACT,
  301. TCA_CGROUP_POLICE,
  302. TCA_CGROUP_EMATCHES,
  303. __TCA_CGROUP_MAX,
  304. };
  305. #define TCA_CGROUP_MAX (__TCA_CGROUP_MAX - 1)
  306. /* BPF classifier */
  307. #define TCA_BPF_FLAG_ACT_DIRECT (1 << 0)
  308. enum {
  309. TCA_BPF_UNSPEC,
  310. TCA_BPF_ACT,
  311. TCA_BPF_POLICE,
  312. TCA_BPF_CLASSID,
  313. TCA_BPF_OPS_LEN,
  314. TCA_BPF_OPS,
  315. TCA_BPF_FD,
  316. TCA_BPF_NAME,
  317. TCA_BPF_FLAGS,
  318. __TCA_BPF_MAX,
  319. };
  320. #define TCA_BPF_MAX (__TCA_BPF_MAX - 1)
  321. /* Flower classifier */
  322. enum {
  323. TCA_FLOWER_UNSPEC,
  324. TCA_FLOWER_CLASSID,
  325. TCA_FLOWER_INDEV,
  326. TCA_FLOWER_ACT,
  327. TCA_FLOWER_KEY_ETH_DST, /* ETH_ALEN */
  328. TCA_FLOWER_KEY_ETH_DST_MASK, /* ETH_ALEN */
  329. TCA_FLOWER_KEY_ETH_SRC, /* ETH_ALEN */
  330. TCA_FLOWER_KEY_ETH_SRC_MASK, /* ETH_ALEN */
  331. TCA_FLOWER_KEY_ETH_TYPE, /* be16 */
  332. TCA_FLOWER_KEY_IP_PROTO, /* u8 */
  333. TCA_FLOWER_KEY_IPV4_SRC, /* be32 */
  334. TCA_FLOWER_KEY_IPV4_SRC_MASK, /* be32 */
  335. TCA_FLOWER_KEY_IPV4_DST, /* be32 */
  336. TCA_FLOWER_KEY_IPV4_DST_MASK, /* be32 */
  337. TCA_FLOWER_KEY_IPV6_SRC, /* struct in6_addr */
  338. TCA_FLOWER_KEY_IPV6_SRC_MASK, /* struct in6_addr */
  339. TCA_FLOWER_KEY_IPV6_DST, /* struct in6_addr */
  340. TCA_FLOWER_KEY_IPV6_DST_MASK, /* struct in6_addr */
  341. TCA_FLOWER_KEY_TCP_SRC, /* be16 */
  342. TCA_FLOWER_KEY_TCP_DST, /* be16 */
  343. TCA_FLOWER_KEY_UDP_SRC, /* be16 */
  344. TCA_FLOWER_KEY_UDP_DST, /* be16 */
  345. __TCA_FLOWER_MAX,
  346. };
  347. #define TCA_FLOWER_MAX (__TCA_FLOWER_MAX - 1)
  348. /* Extended Matches */
  349. struct tcf_ematch_tree_hdr {
  350. __u16 nmatches;
  351. __u16 progid;
  352. };
  353. enum {
  354. TCA_EMATCH_TREE_UNSPEC,
  355. TCA_EMATCH_TREE_HDR,
  356. TCA_EMATCH_TREE_LIST,
  357. __TCA_EMATCH_TREE_MAX
  358. };
  359. #define TCA_EMATCH_TREE_MAX (__TCA_EMATCH_TREE_MAX - 1)
  360. struct tcf_ematch_hdr {
  361. __u16 matchid;
  362. __u16 kind;
  363. __u16 flags;
  364. __u16 pad; /* currently unused */
  365. };
  366. /* 0 1
  367. * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
  368. * +-----------------------+-+-+---+
  369. * | Unused |S|I| R |
  370. * +-----------------------+-+-+---+
  371. *
  372. * R(2) ::= relation to next ematch
  373. * where: 0 0 END (last ematch)
  374. * 0 1 AND
  375. * 1 0 OR
  376. * 1 1 Unused (invalid)
  377. * I(1) ::= invert result
  378. * S(1) ::= simple payload
  379. */
  380. #define TCF_EM_REL_END 0
  381. #define TCF_EM_REL_AND (1<<0)
  382. #define TCF_EM_REL_OR (1<<1)
  383. #define TCF_EM_INVERT (1<<2)
  384. #define TCF_EM_SIMPLE (1<<3)
  385. #define TCF_EM_REL_MASK 3
  386. #define TCF_EM_REL_VALID(v) (((v) & TCF_EM_REL_MASK) != TCF_EM_REL_MASK)
  387. enum {
  388. TCF_LAYER_LINK,
  389. TCF_LAYER_NETWORK,
  390. TCF_LAYER_TRANSPORT,
  391. __TCF_LAYER_MAX
  392. };
  393. #define TCF_LAYER_MAX (__TCF_LAYER_MAX - 1)
  394. /* Ematch type assignments
  395. * 1..32767 Reserved for ematches inside kernel tree
  396. * 32768..65535 Free to use, not reliable
  397. */
  398. #define TCF_EM_CONTAINER 0
  399. #define TCF_EM_CMP 1
  400. #define TCF_EM_NBYTE 2
  401. #define TCF_EM_U32 3
  402. #define TCF_EM_META 4
  403. #define TCF_EM_TEXT 5
  404. #define TCF_EM_VLAN 6
  405. #define TCF_EM_CANID 7
  406. #define TCF_EM_IPSET 8
  407. #define TCF_EM_MAX 8
  408. enum {
  409. TCF_EM_PROG_TC
  410. };
  411. enum {
  412. TCF_EM_OPND_EQ,
  413. TCF_EM_OPND_GT,
  414. TCF_EM_OPND_LT
  415. };
  416. #endif