Bug 239506 - ipfw logging doesn't work
Summary: ipfw logging doesn't work
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 12.0-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-ipfw (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-07-29 03:13 UTC by Yuri Victorovich
Modified: 2022-09-02 23:45 UTC (History)
3 users (show)

See Also:


Attachments
Proposed patch (untested) (2.09 KB, patch)
2019-08-06 12:41 UTC, Andrey V. Elsukov
no flags Details | Diff
Proposed patch (untested) (2.23 KB, patch)
2019-08-06 12:47 UTC, Andrey V. Elsukov
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yuri Victorovich freebsd_committer freebsd_triage 2019-07-29 03:13:14 UTC
/etc/rc.conf has:
> firewall_enable="YES"
> firewall_type="open"
> firewall_logif="YES"

I know for a fact that the 'nat' ipfw rule with a "log" keyword works:
> ipfw -q nat 59000 config ip 192.168.5.3 reset log

But tcpdump complains about the promiscuous mode and doesn't log anything:
> # tcpdump -t -n -i ipfw0
> tcpdump: WARNING: ipfw0: That device doesn't support promiscuous mode
> (BIOCPROMISC: Invalid argument)
> tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
> listening on ipfw0, link-type EN10MB (Ethernet), capture size 262144 bytes

FreeBSD 12.0-STABLE r347548
Comment 1 Andrey V. Elsukov freebsd_committer freebsd_triage 2019-07-29 07:33:03 UTC
AFAIK, it never worked like this. NAT has its own logging facilities and it doesn't know how to use BPF.
Comment 2 Yuri Victorovich freebsd_committer freebsd_triage 2019-07-29 07:41:50 UTC
In the ipfw(8) manpage, under the section "IPv6/IPv4 NETWORK ADDRESS AND PROTOCOL TRANSLATION" it says:

>     log     Turn on logging of all handled packets via BPF through ipfwlog0
>             interface.  ipfwlog0 is a pseudo interface and can be created
>             after a boot manually with ifconfig command.  Note that it has
>             different purpose than ipfw0 interface.  Translators sends to BPF
>             an additional information with each packet.  With tcpdump you are
>             able to see each handled packet before and after translation.

Does this mean that the manpage contains a wrong information?
Comment 3 Andrey V. Elsukov freebsd_committer freebsd_triage 2019-07-29 07:43:30 UTC
(In reply to Yuri Victorovich from comment #2)
> In the ipfw(8) manpage, under the section "IPv6/IPv4 NETWORK ADDRESS AND
> PROTOCOL TRANSLATION" it says:
> 
> >     log     Turn on logging of all handled packets via BPF through ipfwlog0
> >             interface.  ipfwlog0 is a pseudo interface and can be created
> >             after a boot manually with ifconfig command.  Note that it has
> >             different purpose than ipfw0 interface.  Translators sends to BPF
> >             an additional information with each packet.  With tcpdump you are
> >             able to see each handled packet before and after translation.
> 
> Does this mean that the manpage contains a wrong information?

This entry belogns to NAT64 module, it should work.
Comment 4 Yuri Victorovich freebsd_committer freebsd_triage 2019-07-29 07:50:11 UTC
I see, this is for ipfw_nat64. I don't think that this manpage describes how to use logging with ipfw_nat.
Comment 5 Andrey V. Elsukov freebsd_committer freebsd_triage 2019-07-29 07:55:12 UTC
(In reply to Yuri Victorovich from comment #4)
> I see, this is for ipfw_nat64. I don't think that this manpage describes how
> to use logging with ipfw_nat.

It looks like something should be showed by `ipfw nat N show log` command. :)
Comment 6 Yuri Victorovich freebsd_committer freebsd_triage 2019-07-29 08:06:45 UTC
(In reply to Andrey V. Elsukov from comment #5)

No, actually:
> $ sudo ipfw nat 998 show log
> ipfw: Error getting nat 998 instance info: No such file or directory

kernel log:
> 78332 ipfw     CALL  socket(PF_INET,0x3<SOCK_RAW>,IPPROTO_RAW)
> 78332 ipfw     RET   socket 3
> 78332 ipfw     CALL  getsockopt(0x3,IPPROTO_IP,IP_FW3,0x800697000,0x7fffffffd92c)
> 78332 ipfw     RET   getsockopt -1 errno 2 No such file or directory
> 78332 ipfw     CALL  write(0x2,0x7fffffffd180,0x6)
> 78332 ipfw     GIO   fd 2 wrote 6 bytes
>       "ipfw: "
> 78332 ipfw     RET   write 6
> 78332 ipfw     CALL  write(0x2,0x7fffffffd280,0x23)
> 78332 ipfw     GIO   fd 2 wrote 35 bytes
>       "Error getting nat 998 instance info"



'sudo ipfw nat 998 show config' works though.
Comment 7 Yuri Victorovich freebsd_committer freebsd_triage 2019-07-29 08:11:25 UTC
(In reply to Yuri Victorovich from comment #6)

Sorry, I take this back. "log" wasn't in it.
Now it shows something.
Comment 8 Yuri Victorovich freebsd_committer freebsd_triage 2019-07-29 08:15:02 UTC
It shows this:

> # ipfw nat 998 show log
> ipfw: unknown redir mode
> ipfw nat 998 config log reset reverse[root@yv /tmp]#

I was expecting to see the log of packets. It definitely altered some packets.
Comment 9 Andrey V. Elsukov freebsd_committer freebsd_triage 2019-07-29 10:33:22 UTC
This doesn't look very hard to add such support. I'll try this at the end of week. 
For now you can add "count log" rule just after nat rule, in case of one_pass=0 it will show translated packets.
Comment 10 Andrey V. Elsukov freebsd_committer freebsd_triage 2019-08-06 12:41:52 UTC
Created attachment 206306 [details]
Proposed patch (untested)

Can you try this patch?
It adds to ipfw_nat module support of logging via ipfwlog0.
You need to rebuild kernel or ipfw_nat kernel module, then create ipfwlog0 interface and enable logging with "log" keyword in the nat instance.
Then you can capture packets before translation and after.
The only exception is "nat global", packets before translation will not be captured for such configuration.
Comment 11 Andrey V. Elsukov freebsd_committer freebsd_triage 2019-08-06 12:47:19 UTC
Created attachment 206307 [details]
Proposed patch (untested)

Added rule number to the logging info.
Comment 12 Mark Johnston freebsd_committer freebsd_triage 2020-07-13 18:31:14 UTC
Yuri, are you still interested in testing the patch?