public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: Sven Eckelmann <sven@narfation.org>
Subject: [B.A.T.M.A.N.] [PATCH 2/2] alfred: Bind alfred to a specific device
Date: Tue, 29 Jul 2014 14:06:54 +0200	[thread overview]
Message-ID: <1406635614-28176-2-git-send-email-sven@narfation.org> (raw)
In-Reply-To: <1406635614-28176-1-git-send-email-sven@narfation.org>

It is necessary to bind the alfred process to a specific device to allow
multiple instances of it to run at the same time but on different network
interfaces. Just using the scope_id with IPv6 is not enough to bind only on
this specific network device. Also using a specific address+port would not work
because then the master announcements would not be received anymore.

The bind to device only works when the user has root privileges. Therefore,
alfred must now be started as root.

Reported-by: Tobias Hachmer <tobias@hachmer.de>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
 netsock.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/netsock.c b/netsock.c
index a1a97e4..b59b7b7 100644
--- a/netsock.c
+++ b/netsock.c
@@ -52,7 +52,7 @@ int netsock_open(struct globals *globals)
 
 	globals->netsock = -1;
 
-	sock = socket(PF_INET6, SOCK_DGRAM, 0);
+	sock = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
 	if (sock  < 0) {
 		perror("can't open socket");
 		return -1;
@@ -82,6 +82,12 @@ int netsock_open(struct globals *globals)
 	memcpy(&globals->hwaddr, &ifr.ifr_hwaddr.sa_data, 6);
 	mac_to_ipv6(&globals->hwaddr, &globals->address);
 
+	if (setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE,
+		       globals->interface, strlen(globals->interface) + 1)) {
+		perror("can't bind to device");
+		goto err;
+	}
+
 	if (bind(sock, (struct sockaddr *)&sin6, sizeof(sin6)) < 0) {
 		perror("can't bind");
 		goto err;
-- 
2.0.1


  reply	other threads:[~2014-07-29 12:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-29 12:06 [B.A.T.M.A.N.] [PATCH 1/2] alfred: Print libc errors with perror Sven Eckelmann
2014-07-29 12:06 ` Sven Eckelmann [this message]
2014-07-29 12:37 ` Simon Wunderlich
2014-07-29 16:09   ` Tobias Hachmer

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=1406635614-28176-2-git-send-email-sven@narfation.org \
    --to=sven@narfation.org \
    --cc=b.a.t.m.a.n@lists.open-mesh.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