IPFW Syntax
Q1:
From the man page for IPFW:
'A backslash (`\') can be used to escape the dash (`-') character in a service name (from a shell, the backslash must be typed twice to avoid the shell itself interpreting it as an escape character).'
An example of this 'escaping':
/sbin/ipfw add 10190 set 1 count log proto udp src-ip 192.168.64.0/24 src-port netbios\\-ns dst-ip 192.168.64.255 dst-port netbios\\-ns in recv igb3
When executed the echoed command is:
10190 count log proto udp src-ip 192.168.64.0/24 src-port 137 dst-ip 192.168.64.255 dst-port 137 in recv igb3
My question:
Why does the service name, netbios\\-ns, need escaping and src-port does not?
They both contain a 'dash'.
Q2:
Using the same example but altering it such that dst-port netbios\\-ns is replaced with 137 works as expected:
/sbin/ipfw add 10190 set 1 count log proto udp src-ip 192.168.64.0/24 src-port netbios\\-ns dst-ip 192.168.64.255 dst-port 137 in recv igb3
If dst-port 137 is replaced with dst-port 99999999999999
/sbin/ipfw add 10190 set 1 count log proto udp src-ip 192.168.64.0/24 src-port 137 dst-ip 192.168.64.255 dst-port 99999999999999 in recv igb3
on execution shows:
10190 count log proto udp src-ip 192.168.64.0/24 src-port 137 dst-ip 192.168.64.255 dst-port 16383 in recv igb3
AFAICT:
* The binary represntation of dst-port 99999999999999 when trucated to 16 bits gives dst-port 16383.
* There is no bounds checking on a 'port value' and no syntax error for the rule with dst-port 99999999999999
My question:
Should there be bounds checking on the 'port value'?
Q3:
From the man page for IPFW:
COMMAND OPTIONS
The following general options are available when invoking ipfw:
-n Only check syntax of the command strings, without actually passing them to the kernel.
When used for an 'add' rule the interpreted rule is echoed back to the console and so can be visually validated:
/sbin/ipfw -n add 10190 set 1 count log proto udp src-ip 192.168.64.0/24 src-port netbios\\-ns dst-ip 192.168.64.255 dst-port netbios\\-ns in recv igb3
10190 count log proto udp src-ip 192.168.64.0/24 src-port 137 dst-ip 192.168.64.255 dst-port 137 in recv igb3
When used for a 'nat' rule the interpreted rule is NOT echoed back to the console.
/sbin/ipfw -n nat 10000 config if igb0 log same_ports unreg_only reset redirect_port tcp 172.16.31.252:smtp smtp
It is echoed back when option '-n' is removed:
ipfw nat 10000 config if igb0 log same_ports unreg_only reset redirect_port tcp 172.16.31.252:25 25
My question:
Is there any way to have /sbin/ipfw syntax check a 'nat' rule?
Thanks in advanced for any feedback.
Q1:
From the man page for IPFW:
'A backslash (`\') can be used to escape the dash (`-') character in a service name (from a shell, the backslash must be typed twice to avoid the shell itself interpreting it as an escape character).'
An example of this 'escaping':
/sbin/ipfw add 10190 set 1 count log proto udp src-ip 192.168.64.0/24 src-port netbios\\-ns dst-ip 192.168.64.255 dst-port netbios\\-ns in recv igb3
When executed the echoed command is:
10190 count log proto udp src-ip 192.168.64.0/24 src-port 137 dst-ip 192.168.64.255 dst-port 137 in recv igb3
My question:
Why does the service name, netbios\\-ns, need escaping and src-port does not?
They both contain a 'dash'.
Q2:
Using the same example but altering it such that dst-port netbios\\-ns is replaced with 137 works as expected:
/sbin/ipfw add 10190 set 1 count log proto udp src-ip 192.168.64.0/24 src-port netbios\\-ns dst-ip 192.168.64.255 dst-port 137 in recv igb3
If dst-port 137 is replaced with dst-port 99999999999999
/sbin/ipfw add 10190 set 1 count log proto udp src-ip 192.168.64.0/24 src-port 137 dst-ip 192.168.64.255 dst-port 99999999999999 in recv igb3
on execution shows:
10190 count log proto udp src-ip 192.168.64.0/24 src-port 137 dst-ip 192.168.64.255 dst-port 16383 in recv igb3
AFAICT:
* The binary represntation of dst-port 99999999999999 when trucated to 16 bits gives dst-port 16383.
* There is no bounds checking on a 'port value' and no syntax error for the rule with dst-port 99999999999999
My question:
Should there be bounds checking on the 'port value'?
Q3:
From the man page for IPFW:
COMMAND OPTIONS
The following general options are available when invoking ipfw:
-n Only check syntax of the command strings, without actually passing them to the kernel.
When used for an 'add' rule the interpreted rule is echoed back to the console and so can be visually validated:
/sbin/ipfw -n add 10190 set 1 count log proto udp src-ip 192.168.64.0/24 src-port netbios\\-ns dst-ip 192.168.64.255 dst-port netbios\\-ns in recv igb3
10190 count log proto udp src-ip 192.168.64.0/24 src-port 137 dst-ip 192.168.64.255 dst-port 137 in recv igb3
When used for a 'nat' rule the interpreted rule is NOT echoed back to the console.
/sbin/ipfw -n nat 10000 config if igb0 log same_ports unreg_only reset redirect_port tcp 172.16.31.252:smtp smtp
It is echoed back when option '-n' is removed:
ipfw nat 10000 config if igb0 log same_ports unreg_only reset redirect_port tcp 172.16.31.252:25 25
My question:
Is there any way to have /sbin/ipfw syntax check a 'nat' rule?
Thanks in advanced for any feedback.