From: Jeremy Sowden <jeremy@azazel.net>
To: Jan Engelhardt <jengelh@inai.de>
Cc: Netfilter Devel <netfilter-devel@vger.kernel.org>
Subject: [PATCH xtables-addons 2/3] pknock: pknlusr: fix hard-coded netlink multicast group ID.
Date: Thu, 22 Oct 2020 18:30:04 +0100 [thread overview]
Message-ID: <20201022173006.635720-3-jeremy@azazel.net> (raw)
In-Reply-To: <20201022173006.635720-1-jeremy@azazel.net>
The 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.
Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
extensions/pknock/pknlusr.c | 33 ++++++++++++++++++++++++++++++++-
1 file changed, 32 insertions(+), 1 deletion(-)
diff --git a/extensions/pknock/pknlusr.c b/extensions/pknock/pknlusr.c
index 161a9610a018..ca3af835c9a8 100644
--- a/extensions/pknock/pknlusr.c
+++ b/extensions/pknock/pknlusr.c
@@ -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) {
--
2.28.0
next prev parent reply other threads:[~2020-10-22 17:30 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-22 17:30 [PATCH xtables-addons 0/3] pknlusr improvements Jeremy Sowden
2020-10-22 17:30 ` [PATCH xtables-addons 1/3] pknock: pknlusr: fix formatting Jeremy Sowden
2020-10-22 17:30 ` Jeremy Sowden [this message]
2020-10-23 9:13 ` [PATCH xtables-addons 2/3] pknock: pknlusr: fix hard-coded netlink multicast group ID Jan Engelhardt
2020-10-25 10:58 ` Jeremy Sowden
2020-10-22 17:30 ` [PATCH xtables-addons 3/3] pknock: pknlusr: add man-page Jeremy Sowden
2020-10-23 9:24 ` Jan Engelhardt
2020-10-25 10:59 ` Jeremy Sowden
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201022173006.635720-3-jeremy@azazel.net \
--to=jeremy@azazel.net \
--cc=jengelh@inai.de \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).