]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Allows to configure different remote port for BGP sessions.
authorOndrej Zajicek <santiago@crfreenet.org>
Thu, 2 Oct 2014 09:33:55 +0000 (11:33 +0200)
committerOndrej Zajicek <santiago@crfreenet.org>
Thu, 2 Oct 2014 10:52:50 +0000 (12:52 +0200)
Thanks to João Taveira Araújo for the original patch.

conf/confbase.Y
doc/bird.sgml
proto/bgp/bgp.c
proto/bgp/bgp.h
proto/bgp/config.Y

index cba6fc562b7343fee458095ae29d4a70e048832b..49831b1ab48c46c01f2f08d9fee8aa435b6ec079 100644 (file)
@@ -72,7 +72,7 @@ CF_DECLS
 %token <t> TEXT
 %type <iface> ipa_scope
 
-%type <i> expr bool pxlen
+%type <i> expr bool pxlen ipa_port
 %type <i32> expr_us
 %type <time> datetime
 %type <a> ipa
@@ -88,7 +88,7 @@ CF_DECLS
 %left '!'
 %nonassoc '.'
 
-CF_KEYWORDS(DEFINE, ON, OFF, YES, NO, S, MS, US)
+CF_KEYWORDS(DEFINE, ON, OFF, YES, NO, S, MS, US, PORT)
 
 CF_GRAMMAR
 
@@ -161,6 +161,14 @@ ipa_scope:
  | '%' SYM { $$ = if_get_by_name($2->name); }
  ;
 
+ipa_port:
+   /* empty */ { $$ = 0; }
+ | PORT expr {
+     if (($2 < 1) || ($2 > 65535)) cf_error("Invalid port number");
+     $$ = $2;
+   }
+ ;
+
 prefix:
    ipa pxlen {
      if (!ip_is_prefix($1, $2)) cf_error("Invalid prefix");
index 1a8e233d644da5f2657a210dd579265e88eb2275..8f2e69351817b7e495214c8f5676f53030a1d110 100644 (file)
@@ -1004,7 +1004,6 @@ foot).
        So <cf>1.2.0.0/16.pxlen = 16</cf> is true.
 
        <tag/ec/
-
        This is a specialized type used to represent BGP extended community
        values. It is essentially a 64bit value, literals of this type are
        usually written as <cf>(<m/kind/, <m/key/, <m/value/)</cf>, where
@@ -1014,7 +1013,7 @@ foot).
        used kind. Similarly to pairs, ECs can be constructed using expressions
        for <cf/key/ and <cf/value/ parts, (e.g. <cf/(ro, myas, 3*10)/, where
        <cf/myas/ is an integer variable).
+
        <tag/int|pair|quad|ip|prefix|ec|enum set/
        Filters recognize four types of sets. Sets are similar to strings: you
        can pass them around but you can't modify them. Literals of type <cf>int
@@ -1616,7 +1615,7 @@ using the following configuration parameters:
        address, equivalent to the <cf/source address/ option (see below). This
        parameter is mandatory.
 
-       <tag>neighbor <m/ip/ as <m/number/</tag>
+       <tag>neighbor <m/ip/ [port <m/number/] as <m/number/</tag>
        Define neighboring router this instance will be talking to and what AS
        it's located in. In case the neighbor is in the same AS as we are, we
        automatically switch to iBGP. This parameter is mandatory.
index b6239971a70751d3d31290a6f622d3821a1bafcd..e2339112dbd79e97c528ea4b9f969f272abbe6e4 100644 (file)
@@ -680,8 +680,8 @@ bgp_connect(struct bgp_proto *p)    /* Enter Connect state and start establishing c
   s->type = SK_TCP_ACTIVE;
   s->saddr = p->source_addr;
   s->daddr = p->cf->remote_ip;
+  s->dport = p->cf->remote_port;
   s->iface = p->neigh ? p->neigh->iface : NULL;
-  s->dport = BGP_PORT;
   s->ttl = p->cf->ttl_security ? 255 : hops;
   s->rbsize = BGP_RX_BUFFER_SIZE;
   s->tbsize = BGP_TX_BUFFER_SIZE;
@@ -1016,9 +1016,9 @@ bgp_start(struct proto *P)
 
   lock = p->lock = olock_new(P->pool);
   lock->addr = p->cf->remote_ip;
+  lock->port = p->cf->remote_port;
   lock->iface = p->cf->iface;
   lock->type = OBJLOCK_TCP;
-  lock->port = BGP_PORT;
   lock->hook = bgp_start_locked;
   lock->data = p;
   olock_acquire(lock);
index da0114c2b2afe3f1efd2831a2359f9f450337a63..0fd3a73c81ba9cd5e8d11f4a17e0186dccaa03eb 100644 (file)
@@ -23,6 +23,7 @@ struct bgp_config {
   ip_addr remote_ip;
   ip_addr source_addr;                 /* Source address to use */
   struct iface *iface;                 /* Interface for link-local addresses */
+  u16 remote_port;                     /* Neighbor destination port */
   int multihop;                                /* Number of hops if multihop */
   int ttl_security;                    /* Enable TTL security [RFC5082] */
   int next_hop_self;                   /* Always set next hop to local IP address */
index 4d085d420b2bfa028053a564a777f7c947e42665..8e0b241261902e9428467f0cfae37166fadd876a 100644 (file)
@@ -60,7 +60,7 @@ bgp_proto:
  | bgp_proto proto_item ';'
  | bgp_proto LOCAL AS expr ';' { BGP_CFG->local_as = $4; }
  | bgp_proto LOCAL ipa AS expr ';' { BGP_CFG->source_addr = $3; BGP_CFG->local_as = $5; }
- | bgp_proto NEIGHBOR ipa ipa_scope AS expr ';' {
+ | bgp_proto NEIGHBOR ipa ipa_scope ipa_port AS expr ';' {
      if (ipa_nonzero(BGP_CFG->remote_ip))
        cf_error("Only one neighbor per BGP instance is allowed");
      if (!ipa_has_link_scope($3) != !$4)
@@ -68,7 +68,8 @@ bgp_proto:
 
      BGP_CFG->remote_ip = $3;
      BGP_CFG->iface = $4;
-     BGP_CFG->remote_as = $6;
+     BGP_CFG->remote_port = ($5 > 0) ? $5 : BGP_PORT;
+     BGP_CFG->remote_as = $7;
    }
  | bgp_proto RR CLUSTER ID idval ';' { BGP_CFG->rr_cluster_id = $5; }
  | bgp_proto RR CLIENT ';' { BGP_CFG->rr_client = 1; }