nft_masq.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (c) 2014 Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/init.h>
  10. #include <linux/module.h>
  11. #include <linux/netlink.h>
  12. #include <linux/netfilter.h>
  13. #include <linux/netfilter/nf_tables.h>
  14. #include <net/netfilter/nf_tables.h>
  15. #include <net/netfilter/nf_nat.h>
  16. #include <net/netfilter/nft_masq.h>
  17. const struct nla_policy nft_masq_policy[NFTA_MASQ_MAX + 1] = {
  18. [NFTA_MASQ_FLAGS] = { .type = NLA_U32 },
  19. };
  20. EXPORT_SYMBOL_GPL(nft_masq_policy);
  21. int nft_masq_init(const struct nft_ctx *ctx,
  22. const struct nft_expr *expr,
  23. const struct nlattr * const tb[])
  24. {
  25. struct nft_masq *priv = nft_expr_priv(expr);
  26. int err;
  27. err = nft_chain_validate_dependency(ctx->chain, NFT_CHAIN_T_NAT);
  28. if (err < 0)
  29. return err;
  30. if (tb[NFTA_MASQ_FLAGS] == NULL)
  31. return 0;
  32. priv->flags = ntohl(nla_get_be32(tb[NFTA_MASQ_FLAGS]));
  33. if (priv->flags & ~NF_NAT_RANGE_MASK)
  34. return -EINVAL;
  35. return 0;
  36. }
  37. EXPORT_SYMBOL_GPL(nft_masq_init);
  38. int nft_masq_dump(struct sk_buff *skb, const struct nft_expr *expr)
  39. {
  40. const struct nft_masq *priv = nft_expr_priv(expr);
  41. if (priv->flags == 0)
  42. return 0;
  43. if (nla_put_be32(skb, NFTA_MASQ_FLAGS, htonl(priv->flags)))
  44. goto nla_put_failure;
  45. return 0;
  46. nla_put_failure:
  47. return -1;
  48. }
  49. EXPORT_SYMBOL_GPL(nft_masq_dump);
  50. int nft_masq_validate(const struct nft_ctx *ctx, const struct nft_expr *expr,
  51. const struct nft_data **data)
  52. {
  53. return nft_chain_validate_dependency(ctx->chain, NFT_CHAIN_T_NAT);
  54. }
  55. EXPORT_SYMBOL_GPL(nft_masq_validate);
  56. MODULE_LICENSE("GPL");
  57. MODULE_AUTHOR("Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>");