You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
3.3 KiB

  1. --- a/src/build.c
  2. +++ b/src/build.c
  3. @@ -66,7 +66,14 @@ ct_build_u32(const struct nf_conntrack *
  4. }
  5. static inline void
  6. -ct_build_u128(const struct nf_conntrack *ct, int a, struct nethdr *n, int b)
  7. +ct_build_be32(const struct nf_conntrack *ct, int a, struct nethdr *n, int b)
  8. +{
  9. + uint32_t data = nfct_get_attr_u32(ct, a);
  10. + addattr(n, b, &data, sizeof(uint32_t));
  11. +}
  12. +
  13. +static inline void
  14. +ct_build_be128(const struct nf_conntrack *ct, int a, struct nethdr *n, int b)
  15. {
  16. const char *data = nfct_get_attr(ct, a);
  17. addattr(n, b, data, sizeof(uint32_t) * 4);
  18. @@ -279,18 +286,18 @@ void ct2msg(const struct nf_conntrack *c
  19. switch (nfct_get_attr_u8(ct, ATTR_ORIG_L3PROTO)) {
  20. case AF_INET:
  21. if (nfct_getobjopt(ct, NFCT_GOPT_IS_SNAT))
  22. - ct_build_u32(ct, ATTR_REPL_IPV4_DST, n, NTA_SNAT_IPV4);
  23. + ct_build_be32(ct, ATTR_REPL_IPV4_DST, n, NTA_SNAT_IPV4);
  24. if (nfct_getobjopt(ct, NFCT_GOPT_IS_DNAT))
  25. - ct_build_u32(ct, ATTR_REPL_IPV4_SRC, n, NTA_DNAT_IPV4);
  26. + ct_build_be32(ct, ATTR_REPL_IPV4_SRC, n, NTA_DNAT_IPV4);
  27. break;
  28. case AF_INET6:
  29. if (nfct_getobjopt(ct, NFCT_GOPT_IS_SNAT)) {
  30. - ct_build_u128(ct, ATTR_REPL_IPV6_DST, n,
  31. - NTA_SNAT_IPV6);
  32. + ct_build_be128(ct, ATTR_REPL_IPV6_DST, n,
  33. + NTA_SNAT_IPV6);
  34. }
  35. if (nfct_getobjopt(ct, NFCT_GOPT_IS_DNAT)) {
  36. - ct_build_u128(ct, ATTR_REPL_IPV6_SRC, n,
  37. - NTA_DNAT_IPV6);
  38. + ct_build_be128(ct, ATTR_REPL_IPV6_SRC, n,
  39. + NTA_DNAT_IPV6);
  40. }
  41. break;
  42. default:
  43. --- a/src/parse.c
  44. +++ b/src/parse.c
  45. @@ -29,7 +29,8 @@
  46. static void ct_parse_u8(struct nf_conntrack *ct, int attr, void *data);
  47. static void ct_parse_u16(struct nf_conntrack *ct, int attr, void *data);
  48. static void ct_parse_u32(struct nf_conntrack *ct, int attr, void *data);
  49. -static void ct_parse_u128(struct nf_conntrack *ct, int attr, void *data);
  50. +static void ct_parse_be32(struct nf_conntrack *ct, int attr, void *data);
  51. +static void ct_parse_be128(struct nf_conntrack *ct, int attr, void *data);
  52. static void ct_parse_str(struct nf_conntrack *ct,
  53. const struct netattr *, void *data);
  54. static void ct_parse_group(struct nf_conntrack *ct, int attr, void *data);
  55. @@ -108,12 +109,12 @@ static struct ct_parser h[NTA_MAX] = {
  56. .size = NTA_SIZE(sizeof(struct nfct_attr_grp_port)),
  57. },
  58. [NTA_SNAT_IPV4] = {
  59. - .parse = ct_parse_u32,
  60. + .parse = ct_parse_be32,
  61. .attr = ATTR_SNAT_IPV4,
  62. .size = NTA_SIZE(sizeof(uint32_t)),
  63. },
  64. [NTA_DNAT_IPV4] = {
  65. - .parse = ct_parse_u32,
  66. + .parse = ct_parse_be32,
  67. .attr = ATTR_DNAT_IPV4,
  68. .size = NTA_SIZE(sizeof(uint32_t)),
  69. },
  70. @@ -192,12 +193,12 @@ static struct ct_parser h[NTA_MAX] = {
  71. .max_size = NTA_SIZE(NTA_LABELS_MAX_SIZE),
  72. },
  73. [NTA_SNAT_IPV6] = {
  74. - .parse = ct_parse_u128,
  75. + .parse = ct_parse_be128,
  76. .attr = ATTR_SNAT_IPV6,
  77. .size = NTA_SIZE(sizeof(uint32_t) * 4),
  78. },
  79. [NTA_DNAT_IPV6] = {
  80. - .parse = ct_parse_u128,
  81. + .parse = ct_parse_be128,
  82. .attr = ATTR_DNAT_IPV6,
  83. .size = NTA_SIZE(sizeof(uint32_t) * 4),
  84. },
  85. @@ -229,7 +230,14 @@ ct_parse_u32(struct nf_conntrack *ct, in
  86. }
  87. static void
  88. -ct_parse_u128(struct nf_conntrack *ct, int attr, void *data)
  89. +ct_parse_be32(struct nf_conntrack *ct, int attr, void *data)
  90. +{
  91. + uint32_t *value = (uint32_t *) data;
  92. + nfct_set_attr_u32(ct, h[attr].attr, *value);
  93. +}
  94. +
  95. +static void
  96. +ct_parse_be128(struct nf_conntrack *ct, int attr, void *data)
  97. {
  98. nfct_set_attr(ct, h[attr].attr, data);
  99. }