[Babel-users] [PATCH 2/2] interface.c: interface_set_status() minor refactoring
Christof Schulze
christof.schulze at gmx.net
Mon Jul 1 00:19:04 BST 2019
* clarify code flow, only checking for future state once
* clarify error messages when MTU is guessed by including the MTU value
* remove useless comment about the need to run an IP check that already
is run
* allocate exactly as much space as required. Not more for good luck
---
interface.c | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/interface.c b/interface.c
index 4feea7e..f4629ab 100644
--- a/interface.c
+++ b/interface.c
@@ -279,12 +279,8 @@ interface_set_status(struct interface *ifp, int up)
if((!!up) == if_up(ifp))
return 0;
- if(up)
- ifp->flags |= IF_UP;
- else
- ifp->flags &= ~IF_UP;
-
if(up) {
+ ifp->flags |= IF_UP;
if(ifp->ifindex <= 0) {
fprintf(stderr,
"Upping unknown interface %s.\n", ifp->name);
@@ -306,7 +302,7 @@ interface_set_status(struct interface *ifp, int up)
mtu = kernel_interface_mtu(ifp->name, ifp->ifindex);
if(mtu < 0) {
- fprintf(stderr, "Warning: couldn't get MTU of interface %s (%u).\n",
+ fprintf(stderr, "Warning: couldn't get MTU of interface %s (%u), using 1280.\n",
ifp->name, ifp->ifindex);
mtu = 1280;
}
@@ -316,7 +312,7 @@ interface_set_status(struct interface *ifp, int up)
/* In IPv6, the minimum MTU is 1280, and every host must be able
to reassemble up to 1500 bytes, but I'd rather not rely on this. */
if(mtu < 128) {
- fprintf(stderr, "Suspiciously low MTU %d on interface %s (%u).\n",
+ fprintf(stderr, "Suspiciously low MTU %d on interface %s (%u), using 128 and require lower-level fragmentation.\n",
mtu, ifp->name, ifp->ifindex);
mtu = 128;
}
@@ -324,8 +320,8 @@ interface_set_status(struct interface *ifp, int up)
if(ifp->buf.buf)
free(ifp->buf.buf);
- /* 40 for IPv6 header, 8 for UDP header, 12 for good luck. */
- ifp->buf.size = mtu - sizeof(packet_header) - 60;
+ /* 40 for IPv6 header, 8 for UDP header */
+ ifp->buf.size = mtu - sizeof(packet_header) - ( 40 + 8 );
ifp->buf.buf = malloc(ifp->buf.size);
if(ifp->buf.buf == NULL) {
fprintf(stderr, "Couldn't allocate sendbuf.\n");
@@ -483,6 +479,7 @@ interface_set_status(struct interface *ifp, int up)
send_update(ifp, 0, NULL, 0, NULL, 0);
send_multicast_request(ifp, NULL, 0, NULL, 0);
} else {
+ ifp->flags &= ~IF_UP;
flush_interface_routes(ifp, 0);
ifp->buf.len = 0;
ifp->buf.size = 0;
@@ -559,8 +556,6 @@ check_interfaces(void)
}
if(if_up(ifp)) {
- /* Bother, said Pooh. We should probably check for a change
- in IPv4 addresses at this point. */
check_link_local_addresses(ifp);
check_interface_channel(ifp);
rc = check_interface_ipv4(ifp);
--
2.11.0
More information about the Babel-users
mailing list