pknlusr improvements
cover pknlusr improvements
Since pknlusr is now installed, here are a few improvements.
Jeremy Sowden (3):
pknock: pknlusr: fix formatting.
pknock: pknlusr: fix hard-coded netlink multicast group ID.
pknock: pknlusr: add man-page.
extensions/pknock/Makefile.am | 2 ++ extensions/pknock/pknlusr.8 | 23 +++++++++++++++++++++++ extensions/pknock/pknlusr.c | 35 +++++++++++++++++++++++++++++++++-- 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 extensions/pknock/pknlusr.8
Signature · 1 line
2.28.0
PATCH 1/3 pknock: pknlusr: fix formatting.
--- extensions/pknock/pknlusr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
extensions/pknock/pknlusr.c +1 -1
@@ -76,7 +76,7 @@ int main(void)return 1 ; } - nlmsg = (struct xt_pknock_nl_msg *) (buf +sizeof (struct cn_msg ) +sizeof (struct nlmsghdr )); + nlmsg = (struct xt_pknock_nl_msg *) (buf +sizeof (struct cn_msg ) +sizeof (struct nlmsghdr )); ip =inet_ntop (AF_INET , &nlmsg->peer_ip, ipbuf,sizeof (ipbuf));printf ("rule_name: %s - ip %s\n" , nlmsg->rule_name, ip);
Signature · 1 line
2.28.0
PATCH 2/3 pknock: pknlusr: fix hard-coded netlink multicast group ID.
In reply to Jeremy SowdenThe group ID used by xt_pknock is configurable, but pknlusr hard-codes it to 1. Modify pknlusr to accept an optional ID from the command-line.
--- extensions/pknock/pknlusr.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-)
extensions/pknock/pknlusr.c +32 -1
@@ -7,6 +7,8 @@#include <arpa/inet.h> #include <linux/netlink.h> #include <linux/connector.h> +#include <libgen.h> +#include <limits.h> #include "xt_pknock.h"
@@ -19,7 +21,19 @@ static unsigned char *buf;static struct xt_pknock_nl_msg *nlmsg; -int main (void ) +static void +usage (const char *argv0) +{ +char *prog; +if (!(prog =strdup (argv0))) { +perror ("strdup()" ); + }else { +fprintf (stderr,"%s [ group-id ]\n" ,basename (prog)); +free (prog); + } +} + +int main (int argc,char **argv) {socklen_t addrlen;int status;
@@ -30,6 +44,23 @@ int main(void)const char *ip;char ipbuf[48 ]; +if (argc >2 ) { +usage (argv[0 ]); +exit (EXIT_FAILURE ); + } + +if (argc ==2 ) { +long n; +char *end; + + n =strtol (argv[1 ], &end,10 ); +if (*end || n <INT_MIN || n >INT_MAX ) { +usage (argv[0 ]); +exit (EXIT_FAILURE ); + } + group = n; + } + sock_fd =socket (PF_NETLINK ,SOCK_DGRAM ,NETLINK_CONNECTOR );if (sock_fd ==-1 ) {
Signature · 1 line
2.28.0
Re: [PATCH xtables-addons 2/3] pknock: pknlusr: fix hard-coded netlink multicast group ID.
Quoted 2 lines · Jeremy Sowden
The group ID used by
xt_pknockis configurable, but pknlusr hard-codes it to 1. Modify pknlusr to accept an optional ID from the command-line.
According to netlink(7), that is not a group ID but a bitmask of groups. That changes the semantic quite significantly and would make this patch faulty.
extensions/pknock/pknlusr.c int main(void) · line 60
Quoted 5 lines
extensions/pknock/pknlusr.c +5
-0+ n =strtol (argv[1 ], &end,10 ); +if (*end || n <INT_MIN || n >INT_MAX ) { +usage (argv[0 ]); +exit (EXIT_FAILURE ); + }
It's a u32. It can never be less than 0, but it can very well be more than INT_MAX.
Re: [PATCH xtables-addons 2/3] pknock: pknlusr: fix hard-coded netlink multicast group ID.
Quoted 8 lines · Jan Engelhardt
Quoted 3 lines · Jeremy Sowden
The group ID used by
xt_pknockis configurable, but pknlusr hard-codes it to 1. Modify pknlusr to accept an optional ID from the command-line.According to netlink(7), that is not a group ID but a bitmask of groups. That changes the semantic quite significantly and would make this patch faulty.
Yup, v2 will follow shortly.
J.
PATCH 3/3 pknock: pknlusr: add man-page.
In reply to Jeremy SowdenSince pknlusr is now being installed, let's give it a man-page.
--- extensions/pknock/Makefile.am | 2 ++ extensions/pknock/pknlusr.8 | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 extensions/pknock/pknlusr.8
extensions/pknock/Makefile.am +2 -0
@@ -6,3 +6,5 @@ AM_CFLAGS = ${regular_CFLAGS} ${libxtables_CFLAGS} include ../../Makefile.extra sbin_PROGRAMS = pknlusr + +dist_man8_MANS = pknlusr.8
extensions/pknock/pknlusr.8 new file +23 -0
@@ -0,0 +1,23 @@ +.TH pknlusr 8 "2020-10-22" "xtables-addons" "xtables-addons" +. +.SH NAME +pknlusr \- userspace monitor for successful xt_pknock matches +. +.SH SYNOPSIS +.SY pknlusr +.RI [ group-id ] +.YS +. +.SH DESCRIPTION +\fIxt_pknock\fP is an xtables match extension that implements so-called \fIport +knocking\fP. It can be configured to send information about each successful +match via a netlink socket to userspace. \fBpknluser\fP listens for these +notifications. +. +.SH OPTIONS +.TP 9 +.B group-id +The ID of the netlink multicast group used by \fIxt_pknock\fP. Defaults to \fB1\fP. +. +.SH SEE ALSO +.IR xtables-addons (8)
Signature · 1 line
2.28.0
Re: [PATCH xtables-addons 3/3] pknock: pknlusr: add man-page.
Quoted 1 line · Jeremy Sowden
Since pknlusr is now being installed, let's give it a man-page.
There's a lot of.. markup I have never seen before (and thus did not feel would be necessary).
I pushed a shortened version; if anything should be different, please send more patches on top. Thanks!
Re: [PATCH xtables-addons 3/3] pknock: pknlusr: add man-page.
Quoted 5 lines · Jan Engelhardt
Quoted 1 line · Jeremy Sowden
Since pknlusr is now being installed, let's give it a man-page.
There's a lot of.. markup I have never seen before (and thus did not feel would be necessary).
First man-page I've written from scratch in roff. I used the groff_man(7) man-page as a reference.
Quoted 2 lines
I pushed a shortened version; if anything should be different, please send more patches on top.
No problem with the man-page itself, but the patch to Makefile.am isn't quite right. Will fix in v2.
J.