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.

330 lines
7.7 KiB

  1. --- a/pkg/utils/broadcast_rule.go
  2. +++ b/pkg/utils/broadcast_rule.go
  3. @@ -25,7 +25,7 @@ func addPostRoutingBroadcastRule(opts ma
  4. tb := &nftables.Table{
  5. Name: tableName,
  6. - Family: nftables.TableFamilyIPv4,
  7. + Family: nftables.TableFamilyINet,
  8. }
  9. ch := &nftables.Chain{
  10. --- a/pkg/utils/chain_jump_rule.go
  11. +++ b/pkg/utils/chain_jump_rule.go
  12. @@ -26,11 +26,8 @@ func DeleteJumpRule(v, tableName, srcCha
  13. tb := &nftables.Table{
  14. Name: tableName,
  15. }
  16. - if v == "4" {
  17. - tb.Family = nftables.TableFamilyIPv4
  18. - } else {
  19. - tb.Family = nftables.TableFamilyIPv6
  20. - }
  21. +
  22. + tb.Family = nftables.TableFamilyINet
  23. ch := &nftables.Chain{
  24. Name: srcChainName,
  25. @@ -159,11 +156,8 @@ func createJumpRule(v, tableName, srcCha
  26. tb := &nftables.Table{
  27. Name: tableName,
  28. }
  29. - if v == "4" {
  30. - tb.Family = nftables.TableFamilyIPv4
  31. - } else {
  32. - tb.Family = nftables.TableFamilyIPv6
  33. - }
  34. +
  35. + tb.Family = nftables.TableFamilyINet
  36. ch := &nftables.Chain{
  37. Name: srcChainName,
  38. --- a/pkg/utils/chains.go
  39. +++ b/pkg/utils/chains.go
  40. @@ -33,14 +33,8 @@ func IsChainExists(v, tableName, chainNa
  41. if chain.Table.Name != tableName {
  42. continue
  43. }
  44. - if v == "4" {
  45. - if chain.Table.Family != nftables.TableFamilyIPv4 {
  46. - continue
  47. - }
  48. - } else {
  49. - if chain.Table.Family != nftables.TableFamilyIPv6 {
  50. - continue
  51. - }
  52. + if chain.Table.Family != nftables.TableFamilyINet {
  53. + continue
  54. }
  55. return true, nil
  56. }
  57. @@ -100,11 +94,8 @@ func CreateChain(v, tableName, chainName
  58. Name: tableName,
  59. }
  60. - if v == "4" {
  61. - tb.Family = nftables.TableFamilyIPv4
  62. - } else {
  63. - tb.Family = nftables.TableFamilyIPv6
  64. - }
  65. + tb.Family = nftables.TableFamilyINet
  66. +
  67. ch := &nftables.Chain{
  68. Name: chainName,
  69. Table: tb,
  70. @@ -178,11 +169,9 @@ func CreateFilterForwardChain(v, tableNa
  71. tb := &nftables.Table{
  72. Name: tableName,
  73. }
  74. - if v == "4" {
  75. - tb.Family = nftables.TableFamilyIPv4
  76. - } else {
  77. - tb.Family = nftables.TableFamilyIPv6
  78. - }
  79. +
  80. + tb.Family = nftables.TableFamilyINet
  81. +
  82. ch := &nftables.Chain{
  83. Name: chainName,
  84. Table: tb,
  85. @@ -217,11 +206,8 @@ func DeleteChain(v, tableName, chainName
  86. tb := &nftables.Table{
  87. Name: tableName,
  88. }
  89. - if v == "4" {
  90. - tb.Family = nftables.TableFamilyIPv4
  91. - } else {
  92. - tb.Family = nftables.TableFamilyIPv6
  93. - }
  94. +
  95. + tb.Family = nftables.TableFamilyINet
  96. ch := &nftables.Chain{
  97. Name: chainName,
  98. --- a/pkg/utils/dest_nat.go
  99. +++ b/pkg/utils/dest_nat.go
  100. @@ -34,11 +34,8 @@ func AddDestinationNatRules(opts map[str
  101. tb := &nftables.Table{
  102. Name: tableName,
  103. }
  104. - if v == "4" {
  105. - tb.Family = nftables.TableFamilyIPv4
  106. - } else {
  107. - tb.Family = nftables.TableFamilyIPv6
  108. - }
  109. +
  110. + tb.Family = nftables.TableFamilyINet
  111. ch := &nftables.Chain{
  112. Name: chainName,
  113. --- a/pkg/utils/dest_nat_rewrite.go
  114. +++ b/pkg/utils/dest_nat_rewrite.go
  115. @@ -28,11 +28,8 @@ func AddDestinationNatRewriteRules(opts
  116. tb := &nftables.Table{
  117. Name: tableName,
  118. }
  119. - if v == "4" {
  120. - tb.Family = nftables.TableFamilyIPv4
  121. - } else {
  122. - tb.Family = nftables.TableFamilyIPv6
  123. - }
  124. +
  125. + tb.Family = nftables.TableFamilyINet
  126. ch := &nftables.Chain{
  127. Name: chainName,
  128. --- a/pkg/utils/filter_forward_inbound_traffic_rule.go
  129. +++ b/pkg/utils/filter_forward_inbound_traffic_rule.go
  130. @@ -16,11 +16,8 @@ func addFilterForwardInboundTrafficRule(
  131. tb := &nftables.Table{
  132. Name: tableName,
  133. }
  134. - if v == "4" {
  135. - tb.Family = nftables.TableFamilyIPv4
  136. - } else {
  137. - tb.Family = nftables.TableFamilyIPv6
  138. - }
  139. +
  140. + tb.Family = nftables.TableFamilyINet
  141. ch := &nftables.Chain{
  142. Name: chainName,
  143. --- a/pkg/utils/filter_forward_intra_interface_rule.go
  144. +++ b/pkg/utils/filter_forward_intra_interface_rule.go
  145. @@ -16,11 +16,8 @@ func addFilterForwardIntraInterfaceRule(
  146. tb := &nftables.Table{
  147. Name: tableName,
  148. }
  149. - if v == "4" {
  150. - tb.Family = nftables.TableFamilyIPv4
  151. - } else {
  152. - tb.Family = nftables.TableFamilyIPv6
  153. - }
  154. +
  155. + tb.Family = nftables.TableFamilyINet
  156. ch := &nftables.Chain{
  157. Name: chainName,
  158. --- a/pkg/utils/filter_forward_mapped_port_rules.go
  159. +++ b/pkg/utils/filter_forward_mapped_port_rules.go
  160. @@ -32,11 +32,8 @@ func AddFilterForwardMappedPortRules(opt
  161. tb := &nftables.Table{
  162. Name: tableName,
  163. }
  164. - if v == "4" {
  165. - tb.Family = nftables.TableFamilyIPv4
  166. - } else {
  167. - tb.Family = nftables.TableFamilyIPv6
  168. - }
  169. +
  170. + tb.Family = nftables.TableFamilyINet
  171. ch := &nftables.Chain{
  172. Name: chainName,
  173. @@ -247,11 +244,8 @@ func RemoveFilterForwardMappedPortRules(
  174. tb := &nftables.Table{
  175. Name: tableName,
  176. }
  177. - if v == "4" {
  178. - tb.Family = nftables.TableFamilyIPv4
  179. - } else {
  180. - tb.Family = nftables.TableFamilyIPv6
  181. - }
  182. +
  183. + tb.Family = nftables.TableFamilyINet
  184. ch := &nftables.Chain{
  185. Name: chainName,
  186. --- a/pkg/utils/filter_forward_outbound_traffic_rule.go
  187. +++ b/pkg/utils/filter_forward_outbound_traffic_rule.go
  188. @@ -16,11 +16,8 @@ func addFilterForwardOutboundTrafficRule
  189. tb := &nftables.Table{
  190. Name: tableName,
  191. }
  192. - if v == "4" {
  193. - tb.Family = nftables.TableFamilyIPv4
  194. - } else {
  195. - tb.Family = nftables.TableFamilyIPv6
  196. - }
  197. +
  198. + tb.Family = nftables.TableFamilyINet
  199. ch := &nftables.Chain{
  200. Name: chainName,
  201. --- a/pkg/utils/get_chain_props.go
  202. +++ b/pkg/utils/get_chain_props.go
  203. @@ -33,14 +33,8 @@ func GetChainProps(v, tableName, chainNa
  204. var chain *nftables.Chain
  205. for _, c := range chains {
  206. - if v == "4" {
  207. - if c.Table.Family != nftables.TableFamilyIPv4 {
  208. - continue
  209. - }
  210. - } else {
  211. - if c.Table.Family != nftables.TableFamilyIPv6 {
  212. - continue
  213. - }
  214. + if c.Table.Family != nftables.TableFamilyINet {
  215. + continue
  216. }
  217. if chainName != c.Name {
  218. continue
  219. @@ -66,11 +60,8 @@ func GetChainProps(v, tableName, chainNa
  220. tb := &nftables.Table{
  221. Name: tableName,
  222. }
  223. - if v == "4" {
  224. - tb.Family = nftables.TableFamilyIPv4
  225. - } else {
  226. - tb.Family = nftables.TableFamilyIPv6
  227. - }
  228. +
  229. + tb.Family = nftables.TableFamilyINet
  230. ch := &nftables.Chain{
  231. Name: chainName,
  232. --- a/pkg/utils/local_multicast_rule.go
  233. +++ b/pkg/utils/local_multicast_rule.go
  234. @@ -23,11 +23,8 @@ func addPostRoutingLocalMulticastRule(op
  235. tb := &nftables.Table{
  236. Name: tableName,
  237. }
  238. - if v == "4" {
  239. - tb.Family = nftables.TableFamilyIPv4
  240. - } else {
  241. - tb.Family = nftables.TableFamilyIPv6
  242. - }
  243. +
  244. + tb.Family = nftables.TableFamilyINet
  245. ch := &nftables.Chain{
  246. Name: chainName,
  247. --- a/pkg/utils/log_deny_rule.go
  248. +++ b/pkg/utils/log_deny_rule.go
  249. @@ -16,11 +16,8 @@ func addLogDenyRule(v, tableName, chainN
  250. tb := &nftables.Table{
  251. Name: tableName,
  252. }
  253. - if v == "4" {
  254. - tb.Family = nftables.TableFamilyIPv4
  255. - } else {
  256. - tb.Family = nftables.TableFamilyIPv6
  257. - }
  258. +
  259. + tb.Family = nftables.TableFamilyINet
  260. ch := &nftables.Chain{
  261. Name: chainName,
  262. --- a/pkg/utils/source_nat.go
  263. +++ b/pkg/utils/source_nat.go
  264. @@ -29,7 +29,7 @@ func addPostRoutingSourceNatRule(opts ma
  265. tb := &nftables.Table{
  266. Name: tableName,
  267. - Family: nftables.TableFamilyIPv4,
  268. + Family: nftables.TableFamilyINet,
  269. }
  270. ch := &nftables.Chain{
  271. @@ -97,7 +97,7 @@ func AddPostRoutingDestNatRule(opts map[
  272. tb := &nftables.Table{
  273. Name: tableName,
  274. - Family: nftables.TableFamilyIPv4,
  275. + Family: nftables.TableFamilyINet,
  276. }
  277. ch := &nftables.Chain{
  278. --- a/pkg/utils/tables.go
  279. +++ b/pkg/utils/tables.go
  280. @@ -34,14 +34,8 @@ func IsTableExist(v, tableName string) (
  281. if table.Name != tableName {
  282. continue
  283. }
  284. - if v == "4" {
  285. - if table.Family != nftables.TableFamilyIPv4 {
  286. - continue
  287. - }
  288. - } else {
  289. - if table.Family != nftables.TableFamilyIPv6 {
  290. - continue
  291. - }
  292. + if table.Family != nftables.TableFamilyINet {
  293. + continue
  294. }
  295. return true, nil
  296. }
  297. @@ -62,11 +56,7 @@ func CreateTable(v, tableName string) er
  298. t := &nftables.Table{
  299. Name: tableName,
  300. }
  301. - if v == "4" {
  302. - t.Family = nftables.TableFamilyIPv4
  303. - } else {
  304. - t.Family = nftables.TableFamilyIPv6
  305. - }
  306. + t.Family = nftables.TableFamilyINet
  307. conn.AddTable(t)
  308. if err := conn.Flush(); err != nil {
  309. return err