splitice/IPTables.Net

[Bug] Normal rule cause exception

Opened this issue · 1 comments

ITNOA

Hi

I have rule like below

-A INPUT  --protocol tcp --source 2.2.2.2 --destination 1.1.1.1 --source-port 111 --destination-port 222 --jump DROP

I try this rule in iptables command in bash and work correctly, but when I try to create rule for this like below

            IpTablesRule rule = IpTablesRule.Parse($"-A  INPUT  --protocol tcp --source 2.2.2.2 --destination 1.1.1.1 --source-port 111 --destination-port 222 --jump DROP", null, chains);

I got exception

IPTables.Net.Exceptions.IpTablesParserException: Error parsing rule: -A INPUT  --protocol tcp --source 2.2.2.2 --destination 1.1.1.1 --source-port 111 --destination-port 222 --jump DROP
 ---> IPTables.Net.Exceptions.IpTablesNetException: Unknown option: "--source-port"
   at IPTables.Net.Iptables.Modules.CommandParser.FeedToSkip(Int32 position, Boolean not)
   at IPTables.Net.Iptables.IpTablesCommand.Parse(String rule, IpTablesSystem system, IpTablesChainSet chains, CommandParser& parserOut, Int32 version, String defaultTable)
   --- End of inner exception stack trace ---
   at IPTables.Net.Iptables.IpTablesCommand.Parse(String rule, IpTablesSystem system, IpTablesChainSet chains, CommandParser& parserOut, Int32 version, String defaultTable)
   at IPTables.Net.Iptables.IpTablesRule.Parse(String rule, IpTablesSystem system, IpTablesChainSet chains, Int32 version, String defaultTable, ChainCreateMode createChain)
   at BSN.IpTables.Api.Controllers.V1.HomeController.Append(RulesCommandServiceAppendRequest request) in D:\Source\Repos\Resa\IpTables.Api\Source\BSN.IpTables.Api\Controllers\V1\HomeController.cs:line 57
   at lambda_method481(Closure , Object )
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

You need to specify the required module. The implicit -p module loading is not supported (pr welcome).