nf_conntrack_l4proto.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 <net/netfilter/nf_conntrack.h>
  12. struct seq_file;
  13. struct nfattr;
  14. struct nf_conntrack_l4proto
  15. {
  16. /* L3 Protocol number. */
  17. u_int16_t l3proto;
  18. /* L4 Protocol number. */
  19. u_int8_t l4proto;
  20. /* Protocol name */
  21. const char *name;
  22. /* Try to fill in the third arg: dataoff is offset past network protocol
  23. hdr. Return true if possible. */
  24. int (*pkt_to_tuple)(const struct sk_buff *skb,
  25. unsigned int dataoff,
  26. struct nf_conntrack_tuple *tuple);
  27. /* Invert the per-proto part of the tuple: ie. turn xmit into reply.
  28. * Some packets can't be inverted: return 0 in that case.
  29. */
  30. int (*invert_tuple)(struct nf_conntrack_tuple *inverse,
  31. const struct nf_conntrack_tuple *orig);
  32. /* Print out the per-protocol part of the tuple. Return like seq_* */
  33. int (*print_tuple)(struct seq_file *s,
  34. const struct nf_conntrack_tuple *);
  35. /* Print out the private part of the conntrack. */
  36. int (*print_conntrack)(struct seq_file *s, const struct nf_conn *);
  37. /* Returns verdict for packet, or -1 for invalid. */
  38. int (*packet)(struct nf_conn *conntrack,
  39. const struct sk_buff *skb,
  40. unsigned int dataoff,
  41. enum ip_conntrack_info ctinfo,
  42. int pf,
  43. unsigned int hooknum);
  44. /* Called when a new connection for this protocol found;
  45. * returns TRUE if it's OK. If so, packet() called next. */
  46. int (*new)(struct nf_conn *conntrack, const struct sk_buff *skb,
  47. unsigned int dataoff);
  48. /* Called when a conntrack entry is destroyed */
  49. void (*destroy)(struct nf_conn *conntrack);
  50. int (*error)(struct sk_buff *skb, unsigned int dataoff,
  51. enum ip_conntrack_info *ctinfo,
  52. int pf, unsigned int hooknum);
  53. /* convert protoinfo to nfnetink attributes */
  54. int (*to_nfattr)(struct sk_buff *skb, struct nfattr *nfa,
  55. const struct nf_conn *ct);
  56. /* convert nfnetlink attributes to protoinfo */
  57. int (*from_nfattr)(struct nfattr *tb[], struct nf_conn *ct);
  58. int (*tuple_to_nfattr)(struct sk_buff *skb,
  59. const struct nf_conntrack_tuple *t);
  60. int (*nfattr_to_tuple)(struct nfattr *tb[],
  61. struct nf_conntrack_tuple *t);
  62. #ifdef CONFIG_SYSCTL
  63. struct ctl_table_header **ctl_table_header;
  64. struct ctl_table *ctl_table;
  65. unsigned int *ctl_table_users;
  66. #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
  67. struct ctl_table_header *ctl_compat_table_header;
  68. struct ctl_table *ctl_compat_table;
  69. #endif
  70. #endif
  71. /* Module (if any) which this is connected to. */
  72. struct module *me;
  73. };
  74. /* Existing built-in protocols */
  75. extern struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp6;
  76. extern struct nf_conntrack_l4proto nf_conntrack_l4proto_udp4;
  77. extern struct nf_conntrack_l4proto nf_conntrack_l4proto_udp6;
  78. extern struct nf_conntrack_l4proto nf_conntrack_l4proto_generic;
  79. #define MAX_NF_CT_PROTO 256
  80. extern struct nf_conntrack_l4proto **nf_ct_protos[PF_MAX];
  81. extern struct nf_conntrack_l4proto *
  82. __nf_ct_l4proto_find(u_int16_t l3proto, u_int8_t l4proto);
  83. extern struct nf_conntrack_l4proto *
  84. nf_ct_l4proto_find_get(u_int16_t l3proto, u_int8_t protocol);
  85. extern void nf_ct_l4proto_put(struct nf_conntrack_l4proto *p);
  86. /* Protocol registration. */
  87. extern int nf_conntrack_l4proto_register(struct nf_conntrack_l4proto *proto);
  88. extern void nf_conntrack_l4proto_unregister(struct nf_conntrack_l4proto *proto);
  89. /* Generic netlink helpers */
  90. extern int nf_ct_port_tuple_to_nfattr(struct sk_buff *skb,
  91. const struct nf_conntrack_tuple *tuple);
  92. extern int nf_ct_port_nfattr_to_tuple(struct nfattr *tb[],
  93. struct nf_conntrack_tuple *t);
  94. /* Log invalid packets */
  95. extern unsigned int nf_ct_log_invalid;
  96. #ifdef CONFIG_SYSCTL
  97. #ifdef DEBUG_INVALID_PACKETS
  98. #define LOG_INVALID(proto) \
  99. (nf_ct_log_invalid == (proto) || nf_ct_log_invalid == IPPROTO_RAW)
  100. #else
  101. #define LOG_INVALID(proto) \
  102. ((nf_ct_log_invalid == (proto) || nf_ct_log_invalid == IPPROTO_RAW) \
  103. && net_ratelimit())
  104. #endif
  105. #else
  106. #define LOG_INVALID(proto) 0
  107. #endif /* CONFIG_SYSCTL */
  108. #endif /*_NF_CONNTRACK_PROTOCOL_H*/