Send connman mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
https://lists.01.org/mailman/listinfo/connman
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of connman digest..."
Today's Topics:
1. [PATCH] dhcp: Bind to interface when sending (Joakim Lotseng?rd)
----------------------------------------------------------------------
Message: 1
Date: Mon, 26 Aug 2019 14:41:02 +0000
From: Joakim Lotseng?rd <[email protected]>
To: "[email protected]" <[email protected]>
Subject: [PATCH] dhcp: Bind to interface when sending
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Having two interfaces and one goes down, ConnMan previously sent a
DHCP-release only bound to srcIP (via bind), and dstIP, (via connect).
If an interface goes down, the Linux kernel will try to route the
packet any means possible. Effect was that it routed it out on the
other available interface. It might even SNAT the srcIP due to connman
NATing setup.
The result was a very strange DHCP-release. A dstIP of an DHCP-server
that the incorect interface probably could not reach. A srcIP that
seemed correct (due to SNAT rule). An included address to release
inside the DHCP-release that was not the same as the srcIP, but rather
the actual IP to release.
This fixes this via setsockopt(.., SO_BINDTODEVICE, ...) which binds
the socket to the specific interface name, and packets are not seen on
the incorrect interface anymore.
---
gdhcp/client.c | 6 ++++--
gdhcp/common.c | 10 +++++++++-
gdhcp/common.h | 3 ++-
3 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/gdhcp/client.c b/gdhcp/client.c
index aab74378..09dfe5ec 100644
--- a/gdhcp/client.c
+++ b/gdhcp/client.c
@@ -534,7 +534,8 @@ static int send_request(GDHCPClient *dhcp_client)
if (dhcp_client->state == RENEWING)
return dhcp_send_kernel_packet(&packet,
dhcp_client->requested_ip, CLIENT_PORT,
- dhcp_client->server_ip, SERVER_PORT);
+ dhcp_client->server_ip, SERVER_PORT,
+ dhcp_client->interface);
return dhcp_send_raw_packet(&packet, INADDR_ANY, CLIENT_PORT,
INADDR_BROADCAST, SERVER_PORT,
@@ -558,7 +559,8 @@ static int send_release(GDHCPClient *dhcp_client,
dhcp_add_option_uint32(&packet, DHCP_SERVER_ID, server);
return dhcp_send_kernel_packet(&packet, ciaddr, CLIENT_PORT,
- server, SERVER_PORT);
+ server, SERVER_PORT,
+ dhcp_client->interface);
}
static gboolean ipv4ll_probe_timeout(gpointer dhcp_data);
diff --git a/gdhcp/common.c b/gdhcp/common.c
index 8f7a65cc..1d667d17 100644
--- a/gdhcp/common.c
+++ b/gdhcp/common.c
@@ -595,7 +595,8 @@ int dhcp_send_raw_packet(struct dhcp_packet *dhcp_pkt,
int dhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt,
uint32_t source_ip, int source_port,
- uint32_t dest_ip, int dest_port)
+ uint32_t dest_ip, int dest_port,
+ const char *interface)
{
struct sockaddr_in client;
int fd, n, opt = 1;
@@ -609,6 +610,13 @@ int dhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt,
if (fd < 0)
return -errno;
+ if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE,
+ interface, strlen(interface) + 1) < 0) {
+ int err = errno;
+ close(fd);
+ return -err;
+ }
+
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) {
int err = errno;
close(fd);
diff --git a/gdhcp/common.h b/gdhcp/common.h
index 6899499e..9660231c 100644
--- a/gdhcp/common.h
+++ b/gdhcp/common.h
@@ -210,7 +210,8 @@ int dhcp_send_raw_packet(struct dhcp_packet *dhcp_pkt,
int dhcpv6_send_packet(int index, struct dhcpv6_packet *dhcp_pkt, int len);
int dhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt,
uint32_t source_ip, int source_port,
- uint32_t dest_ip, int dest_port);
+ uint32_t dest_ip, int dest_port,
+ const char *interface);
int dhcp_l3_socket(int port, const char *interface, int family);
int dhcp_recv_l3_packet(struct dhcp_packet *packet, int fd);
int dhcpv6_recv_l3_packet(struct dhcpv6_packet **packet, unsigned char *buf,
--
2.17.1
------------------------------
Subject: Digest Footer
_______________________________________________
connman mailing list
[email protected]
https://lists.01.org/mailman/listinfo/connman
------------------------------
End of connman Digest, Vol 46, Issue 24
***************************************