]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Use IP_PORTRANGE_HIGH for BFD where available
authorOndrej Zajicek <santiago@crfreenet.org>
Sun, 22 Feb 2015 19:14:14 +0000 (20:14 +0100)
committerOndrej Zajicek <santiago@crfreenet.org>
Sun, 22 Feb 2015 19:14:14 +0000 (20:14 +0100)
lib/socket.h
proto/bfd/packets.c
sysdep/unix/io.c

index a5b85aa2c0b3f789be3c505c6fc5bf5a1e7d099d..683cdde3d873e67b05960709043d74f73556011f 100644 (file)
@@ -103,6 +103,7 @@ extern int sk_priority_control;             /* Suggested priority for control traffic, shou
 #define SKF_LADDR_RX   0x04    /* Report local address for RX packets */
 #define SKF_TTL_RX     0x08    /* Report TTL / Hop Limit for RX packets */
 #define SKF_BIND       0x10    /* Bind datagram socket to given source address */
+#define SKF_HIGH_PORT  0x20    /* Choose port from high range if possible */
 
 #define SKF_THREAD     0x100   /* Socked used in thread, Do not add to main loop */
 #define SKF_TRUNCATED  0x200   /* Received packet was truncated, set by IO layer */
index 8818453bbde42dc6136394adef5aa5708b1fe97c..b5fd6782b558ae9e4c67f78b8bbd1129a1ae8bec 100644 (file)
@@ -231,7 +231,7 @@ bfd_open_tx_sk(struct bfd_proto *p, ip_addr local, struct iface *ifa)
   sk->tos = IP_PREC_INTERNET_CONTROL;
   sk->priority = sk_priority_control;
   sk->ttl = ifa ? 255 : -1;
-  sk->flags = SKF_THREAD | SKF_BIND;
+  sk->flags = SKF_THREAD | SKF_BIND | SKF_HIGH_PORT;
 
 #ifdef IPV6
   sk->flags |= SKF_V6ONLY;
index 04f0fe505ea4b8a8e1abd664d03015ae3e2fa321..daf9d0546a467a17466f36cdeb545bc351e4c8aa 100644 (file)
@@ -1305,7 +1305,7 @@ sk_passive_connected(sock *s, int type)
     log(L_ERR "SOCK: Incoming connection: %s%#m", t->err);
 
     /* FIXME: handle it better in rfree() */
-    close(t->fd);      
+    close(t->fd);
     t->fd = -1;
     rfree(t);
     return 1;
@@ -1348,7 +1348,7 @@ sk_open(sock *s)
     bind_addr = s->saddr;
     do_bind = bind_port || ipa_nonzero(bind_addr);
     break;
-  
+
   case SK_UDP:
     fd = socket(af, SOCK_DGRAM, IPPROTO_UDP);
     bind_port = s->sport;
@@ -1399,6 +1399,14 @@ sk_open(sock *s)
       }
 #endif
     }
+#ifdef IP_PORTRANGE
+    else if (s->flags & SKF_HIGH_PORT)
+    {
+      int range = IP_PORTRANGE_HIGH;
+      if (setsockopt(fd, IPPROTO_IP, IP_PORTRANGE, &range, sizeof(range)) < 0)
+        log(L_WARN "Socket error: %s%#m", "IP_PORTRANGE");
+    }
+#endif
 
     sockaddr_fill(&sa, af, bind_addr, s->iface, bind_port);
     if (bind(fd, &sa.sa, SA_LEN(sa)) < 0)
@@ -1661,7 +1669,7 @@ sk_rx_ready(sock *s)
 
  redo:
   rv = select(s->fd+1, &rd, &wr, NULL, &timo);
-  
+
   if ((rv < 0) && (errno == EINTR || errno == EAGAIN))
     goto redo;
 
@@ -2026,5 +2034,3 @@ test_old_bird(char *path)
     die("I found another BIRD running.");
   close(fd);
 }
-
-