nf_conntrack_l4proto.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * Header for use in defining a given L4 protocol for connection tracking.
  3. *
  4. * 16 Dec 2003: Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp>
  5. * - generalized L3 protocol dependent part.
  6. *
  7. * Derived from include/linux/netfiter_ipv4/ip_conntrack_protcol.h
  8. */
  9. #ifndef _NF_CONNTRACK_L4PROTO_H
  10. #define _NF_CONNTRACK_L4PROTO_H
  11. #include <linux/netlink.h>
  12. #include <net/netlink.h>
  13. #include <net/netfilter/nf_conntrack.h>
  14. #include <net/netns/generic.h>
  15. struct seq_file;
  16. struct nf_conntrack_l4proto {
  17. /* L3 Protocol number. */
  18. u_int16_t l3proto;
  19. /* L4 Protocol number. */
  20. u_int8_t l4proto;
  21. /* Try to fill in the third arg: dataoff is offset past network protocol
  22. hdr. Return true if possible. */
  23. bool (*pkt_to_tuple)(const struct sk_buff *skb, unsigned int dataoff,
  24. struct net *net, struct nf_conntrack_tuple *tuple);
  25. /* Invert the per-proto part of the tuple: ie. turn xmit into reply.
  26. * Some packets can't be inverted: return 0 in that case.
  27. */
  28. bool (*invert_tuple)(struct nf_conntrack_tuple *inverse,
  29. const struct nf_conntrack_tuple *orig);
  30. /* Returns verdict for packet, or -1 for invalid. */
  31. int (*packet)(struct nf_conn *ct,
  32. const struct sk_buff *skb,
  33. unsigned int dataoff,
  34. enum ip_conntrack_info ctinfo,
  35. u_int8_t pf,
  36. unsigned int hooknum,
  37. unsigned int *timeouts);
  38. /* Called when a new connection for this protocol found;
  39. * returns TRUE if it's OK. If so, packet() called next. */
  40. bool (*new)(struct nf_conn *ct, const struct sk_buff *skb,
  41. unsigned int dataoff, unsigned int *timeouts);
  42. /* Called when a conntrack entry is destroyed */
  43. void (*destroy)(struct nf_conn *ct);
  44. int (*error)(struct net *net, struct nf_conn *tmpl, struct sk_buff *skb,
  45. unsigned int dataoff, enum ip_conntrack_info *ctinfo,
  46. u_int8_t pf, unsigned int hooknum);
  47. /* Print out the per-protocol part of the tuple. Return like seq_* */
  48. void (*print_tuple)(struct seq_file *s,
  49. const struct nf_conntrack_tuple *);
  50. /* Print out the private part of the conntrack. */
  51. void (*print_conntrack)(struct seq_file *s, struct nf_conn *);
  52. /* Return the array of timeouts for this protocol. */
  53. unsigned int *(*get_timeouts)(struct net *net);
  54. /* convert protoinfo to nfnetink attributes */
  55. int (*to_nlattr)(struct sk_buff *skb, struct nlattr *nla,
  56. struct nf_conn *ct);
  57. /* Calculate protoinfo nlattr size */
  58. int (*nlattr_size)(void);
  59. /* convert nfnetlink attributes to protoinfo */
  60. int (*from_nlattr)(struct nlattr *tb[], struct nf_conn *ct);
  61. int (*tuple_to_nlattr)(struct sk_buff *skb,
  62. const struct nf_conntrack_tuple *t);
  63. /* Calculate tuple nlattr size */
  64. int (*nlattr_tuple_size)(void);
  65. int (*nlattr_to_tuple)(struct nlattr *tb[],
  66. struct nf_conntrack_tuple *t);
  67. const struct nla_policy *nla_policy;
  68. size_t nla_size;
  69. #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
  70. struct {
  71. size_t obj_size;
  72. int (*nlattr_to_obj)(struct nlattr *tb[],
  73. struct net *net, void *data);
  74. int (*obj_to_nlattr)(struct sk_buff *skb, const void *data);
  75. unsigned int nlattr_max;
  76. const struct nla_policy *nla_policy;
  77. } ctnl_timeout;
  78. #endif
  79. int *net_id;
  80. /* Init l4proto pernet data */
  81. int (*init_net)(struct net *net, u_int16_t proto);
  82. /* Return the per-net protocol part. */
  83. struct nf_proto_net *(*get_net_proto)(struct net *net);
  84. /* Protocol name */
  85. const char *name;
  86. /* Module (if any) which this is connected to. */
  87. struct module *me;
  88. };
  89. /* Existing built-in generic protocol */
  90. extern struct nf_conntrack_l4proto nf_conntrack_l4proto_generic;
  91. #define MAX_NF_CT_PROTO 256
  92. struct nf_conntrack_l4proto *__nf_ct_l4proto_find(u_int16_t l3proto,
  93. u_int8_t l4proto);
  94. struct nf_conntrack_l4proto *nf_ct_l4proto_find_get(u_int16_t l3proto,
  95. u_int8_t l4proto);
  96. void nf_ct_l4proto_put(struct nf_conntrack_l4proto *p);
  97. /* Protocol pernet registration. */
  98. int nf_ct_l4proto_pernet_register(struct net *net,
  99. struct nf_conntrack_l4proto *proto);
  100. void nf_ct_l4proto_pernet_unregister(struct net *net,
  101. struct nf_conntrack_l4proto *proto);
  102. /* Protocol global registration. */
  103. int nf_ct_l4proto_register(struct nf_conntrack_l4proto *proto);
  104. void nf_ct_l4proto_unregister(struct nf_conntrack_l4proto *proto);
  105. static inline void nf_ct_kfree_compat_sysctl_table(struct nf_proto_net *pn)
  106. {
  107. #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
  108. kfree(pn->ctl_compat_table);
  109. pn->ctl_compat_table = NULL;
  110. #endif
  111. }
  112. /* Generic netlink helpers */
  113. int nf_ct_port_tuple_to_nlattr(struct sk_buff *skb,
  114. const struct nf_conntrack_tuple *tuple);
  115. int nf_ct_port_nlattr_to_tuple(struct nlattr *tb[],
  116. struct nf_conntrack_tuple *t);
  117. int nf_ct_port_nlattr_tuple_size(void);
  118. extern const struct nla_policy nf_ct_port_nla_policy[];
  119. #ifdef CONFIG_SYSCTL
  120. #define LOG_INVALID(net, proto) \
  121. ((net)->ct.sysctl_log_invalid == (proto) || \
  122. (net)->ct.sysctl_log_invalid == IPPROTO_RAW)
  123. #else
  124. static inline int LOG_INVALID(struct net *net, int proto) { return 0; }
  125. #endif /* CONFIG_SYSCTL */
  126. #endif /*_NF_CONNTRACK_PROTOCOL_H*/