500-add-xt_id-match.patch 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. --- /dev/null
  2. +++ b/extensions/libxt_id.c
  3. @@ -0,0 +1,45 @@
  4. +/* Shared library add-on to iptables to add id match support. */
  5. +
  6. +#include <stdio.h>
  7. +#include <xtables.h>
  8. +#include <linux/netfilter/xt_id.h>
  9. +
  10. +enum {
  11. + O_ID = 0,
  12. +};
  13. +
  14. +static const struct xt_option_entry id_opts[] = {
  15. + {
  16. + .name = "id",
  17. + .id = O_ID,
  18. + .type = XTTYPE_UINT32,
  19. + .flags = XTOPT_MAND | XTOPT_PUT,
  20. + XTOPT_POINTER(struct xt_id_info, id)
  21. + },
  22. + XTOPT_TABLEEND,
  23. +};
  24. +
  25. +/* Saves the union ipt_matchinfo in parsable form to stdout. */
  26. +static void
  27. +id_save(const void *ip, const struct xt_entry_match *match)
  28. +{
  29. + struct xt_id_info *idinfo = (void *)match->data;
  30. +
  31. + printf(" --id %lu", idinfo->id);
  32. +}
  33. +
  34. +static struct xtables_match id_match = {
  35. + .family = NFPROTO_UNSPEC,
  36. + .name = "id",
  37. + .version = XTABLES_VERSION,
  38. + .size = XT_ALIGN(sizeof(struct xt_id_info)),
  39. + .userspacesize = XT_ALIGN(sizeof(struct xt_id_info)),
  40. + .save = id_save,
  41. + .x6_parse = xtables_option_parse,
  42. + .x6_options = id_opts,
  43. +};
  44. +
  45. +void _init(void)
  46. +{
  47. + xtables_register_match(&id_match);
  48. +}
  49. --- /dev/null
  50. +++ b/include/linux/netfilter/xt_id.h
  51. @@ -0,0 +1,8 @@
  52. +#ifndef _XT_ID_H
  53. +#define _XT_ID_H
  54. +
  55. +struct xt_id_info {
  56. + __u32 id;
  57. +};
  58. +
  59. +#endif /* XT_ID_H */