nf_nat_l4proto.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* Header for use in defining a given protocol. */
  2. #ifndef _NF_NAT_L4PROTO_H
  3. #define _NF_NAT_L4PROTO_H
  4. #include <net/netfilter/nf_nat.h>
  5. #include <linux/netfilter/nfnetlink_conntrack.h>
  6. struct nf_nat_range;
  7. struct nf_nat_l3proto;
  8. struct nf_nat_l4proto {
  9. /* Protocol number. */
  10. u8 l4proto;
  11. /* Translate a packet to the target according to manip type.
  12. * Return true if succeeded.
  13. */
  14. bool (*manip_pkt)(struct sk_buff *skb,
  15. const struct nf_nat_l3proto *l3proto,
  16. unsigned int iphdroff, unsigned int hdroff,
  17. const struct nf_conntrack_tuple *tuple,
  18. enum nf_nat_manip_type maniptype);
  19. /* Is the manipable part of the tuple between min and max incl? */
  20. bool (*in_range)(const struct nf_conntrack_tuple *tuple,
  21. enum nf_nat_manip_type maniptype,
  22. const union nf_conntrack_man_proto *min,
  23. const union nf_conntrack_man_proto *max);
  24. /* Alter the per-proto part of the tuple (depending on
  25. * maniptype), to give a unique tuple in the given range if
  26. * possible. Per-protocol part of tuple is initialized to the
  27. * incoming packet.
  28. */
  29. void (*unique_tuple)(const struct nf_nat_l3proto *l3proto,
  30. struct nf_conntrack_tuple *tuple,
  31. const struct nf_nat_range *range,
  32. enum nf_nat_manip_type maniptype,
  33. const struct nf_conn *ct);
  34. int (*nlattr_to_range)(struct nlattr *tb[],
  35. struct nf_nat_range *range);
  36. };
  37. /* Protocol registration. */
  38. int nf_nat_l4proto_register(u8 l3proto, const struct nf_nat_l4proto *l4proto);
  39. void nf_nat_l4proto_unregister(u8 l3proto,
  40. const struct nf_nat_l4proto *l4proto);
  41. const struct nf_nat_l4proto *__nf_nat_l4proto_find(u8 l3proto, u8 l4proto);
  42. /* Built-in protocols. */
  43. extern const struct nf_nat_l4proto nf_nat_l4proto_tcp;
  44. extern const struct nf_nat_l4proto nf_nat_l4proto_udp;
  45. extern const struct nf_nat_l4proto nf_nat_l4proto_icmp;
  46. extern const struct nf_nat_l4proto nf_nat_l4proto_icmpv6;
  47. extern const struct nf_nat_l4proto nf_nat_l4proto_unknown;
  48. bool nf_nat_l4proto_in_range(const struct nf_conntrack_tuple *tuple,
  49. enum nf_nat_manip_type maniptype,
  50. const union nf_conntrack_man_proto *min,
  51. const union nf_conntrack_man_proto *max);
  52. void nf_nat_l4proto_unique_tuple(const struct nf_nat_l3proto *l3proto,
  53. struct nf_conntrack_tuple *tuple,
  54. const struct nf_nat_range *range,
  55. enum nf_nat_manip_type maniptype,
  56. const struct nf_conn *ct, u16 *rover);
  57. int nf_nat_l4proto_nlattr_to_range(struct nlattr *tb[],
  58. struct nf_nat_range *range);
  59. #endif /*_NF_NAT_L4PROTO_H*/