0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-22 09:41:54 +00:00

Implements option that changes BGP listening socket parametres.

This commit is contained in:
Ondrej Zajicek 2009-06-18 19:20:07 +02:00
parent 1b3b3e34ec
commit 789772ed45
6 changed files with 48 additions and 5 deletions

View File

@ -175,6 +175,12 @@ global_commit(struct config *new, struct config *old)
{ {
if (!old) if (!old)
return 0; return 0;
if (!ipa_equal(old->bind_bgp_addr, new->bind_bgp_addr) ||
(old->bind_bgp_port != new->bind_bgp_port) ||
(old->bind_bgp_flags != new->bind_bgp_flags))
log(L_WARN "Reconfiguration of BGP listening socket not implemented, please restart BIRD.");
if (!new->router_id) if (!new->router_id)
new->router_id = old->router_id; new->router_id = old->router_id;
if (new->router_id != old->router_id) if (new->router_id != old->router_id)

View File

@ -22,6 +22,9 @@ struct config {
list logfiles; /* Configured log fils (sysdep) */ list logfiles; /* Configured log fils (sysdep) */
struct rtable_config *master_rtc; /* Configuration of master routing table */ struct rtable_config *master_rtc; /* Configuration of master routing table */
u32 router_id; /* Our Router ID */ u32 router_id; /* Our Router ID */
ip_addr bind_bgp_addr; /* Listening BGP socket should use this address */
unsigned bind_bgp_port; /* Listening BGP socket should use this port (0 is default) */
u32 bind_bgp_flags; /* Listening BGP socket should use these flags */
unsigned int proto_default_debug; /* Default protocol debug mask */ unsigned int proto_default_debug; /* Default protocol debug mask */
int cli_debug; /* Tracing of CLI connections and commands */ int cli_debug; /* Tracing of CLI connections and commands */
char *err_msg; /* Parser error message */ char *err_msg; /* Parser error message */

View File

@ -20,6 +20,7 @@ typedef struct birdsock {
unsigned sport, dport; /* 0 = unspecified (for IP: protocol type) */ unsigned sport, dport; /* 0 = unspecified (for IP: protocol type) */
int tos; /* TOS and priority, -1 = default */ int tos; /* TOS and priority, -1 = default */
int ttl; /* Time To Live, -1 = default */ int ttl; /* Time To Live, -1 = default */
u32 flags;
struct iface *iface; /* Interface; specify this for broad/multicast sockets */ struct iface *iface; /* Interface; specify this for broad/multicast sockets */
byte *rbuf, *rpos; /* NULL=allocate automatically */ byte *rbuf, *rpos; /* NULL=allocate automatically */
@ -57,6 +58,12 @@ sk_send_buffer_empty(sock *sk)
return sk->tbuf == sk->tpos; return sk->tbuf == sk->tpos;
} }
/* Socket flags */
#define SKF_V6ONLY 1 /* Use IPV6_V6ONLY socket option */
/* /*
* Socket types SA SP DA DP IF TTL SendTo (?=may, -=must not, *=must) * Socket types SA SP DA DP IF TTL SendTo (?=may, -=must not, *=must)
*/ */

View File

@ -44,6 +44,7 @@ CF_KEYWORDS(ROUTER, ID, PROTOCOL, PREFERENCE, DISABLED, DEBUG, ALL, OFF, DIRECT)
CF_KEYWORDS(INTERFACE, IMPORT, EXPORT, FILTER, NONE, TABLE, STATES, ROUTES, FILTERS) CF_KEYWORDS(INTERFACE, IMPORT, EXPORT, FILTER, NONE, TABLE, STATES, ROUTES, FILTERS)
CF_KEYWORDS(PASSWORD, FROM, PASSIVE, TO, ID, EVENTS, PACKETS, PROTOCOLS, INTERFACES) CF_KEYWORDS(PASSWORD, FROM, PASSIVE, TO, ID, EVENTS, PACKETS, PROTOCOLS, INTERFACES)
CF_KEYWORDS(PRIMARY, STATS, COUNT, FOR, COMMANDS, PREEXPORT, GENERATE) CF_KEYWORDS(PRIMARY, STATS, COUNT, FOR, COMMANDS, PREEXPORT, GENERATE)
CF_KEYWORDS(BIND, BGP, V6ONLY, ADDRESS, PORT)
CF_ENUM(T_ENUM_RTS, RTS_, DUMMY, STATIC, INHERIT, DEVICE, STATIC_DEVICE, REDIRECT, CF_ENUM(T_ENUM_RTS, RTS_, DUMMY, STATIC, INHERIT, DEVICE, STATIC_DEVICE, REDIRECT,
RIP, OSPF, OSPF_IA, OSPF_EXT1, OSPF_EXT2, BGP, PIPE) RIP, OSPF, OSPF_IA, OSPF_EXT1, OSPF_EXT2, BGP, PIPE)
@ -82,6 +83,23 @@ idval:
} }
; ;
CF_ADDTO(conf, bind)
bind: BIND BGP bind_opts ';' ;
bind_opts:
/* Nothing */
| bind_opts bind_opt
;
bind_opt:
ADDRESS ipa { new_config->bind_bgp_addr = $2; }
| PORT expr { new_config->bind_bgp_port = $2; }
| V6ONLY { new_config->bind_bgp_flags |= SKF_V6ONLY; }
;
/* Creation of routing tables */ /* Creation of routing tables */
CF_ADDTO(conf, newtab) CF_ADDTO(conf, newtab)

View File

@ -74,7 +74,7 @@ static int bgp_counter; /* Number of protocol instances using the listening so
static void bgp_close(struct bgp_proto *p, int apply_md5); static void bgp_close(struct bgp_proto *p, int apply_md5);
static void bgp_connect(struct bgp_proto *p); static void bgp_connect(struct bgp_proto *p);
static void bgp_active(struct bgp_proto *p); static void bgp_active(struct bgp_proto *p);
static sock *bgp_setup_listen_sk(void); static sock *bgp_setup_listen_sk(ip_addr addr, unsigned port, u32 flags);
/** /**
@ -90,10 +90,11 @@ static sock *bgp_setup_listen_sk(void);
static int static int
bgp_open(struct bgp_proto *p) bgp_open(struct bgp_proto *p)
{ {
struct config *cfg = p->cf->c.global;
bgp_counter++; bgp_counter++;
if (!bgp_listen_sk) if (!bgp_listen_sk)
bgp_listen_sk = bgp_setup_listen_sk(); bgp_listen_sk = bgp_setup_listen_sk(cfg->bind_bgp_addr, cfg->bind_bgp_port, cfg->bind_bgp_flags);
if (!bgp_linpool) if (!bgp_linpool)
bgp_linpool = lp_new(&root_pool, 4080); bgp_linpool = lp_new(&root_pool, 4080);
@ -587,12 +588,14 @@ bgp_incoming_connection(sock *sk, int dummy UNUSED)
} }
static sock * static sock *
bgp_setup_listen_sk(void) bgp_setup_listen_sk(ip_addr addr, unsigned port, u32 flags)
{ {
sock *s = sk_new(&root_pool); sock *s = sk_new(&root_pool);
DBG("BGP: Creating incoming socket\n"); DBG("BGP: Creating incoming socket\n");
s->type = SK_TCP_PASSIVE; s->type = SK_TCP_PASSIVE;
s->sport = BGP_PORT; s->saddr = addr;
s->sport = port ? port : BGP_PORT;
s->flags = flags;
s->tos = IP_PREC_INTERNET_CONTROL; s->tos = IP_PREC_INTERNET_CONTROL;
s->rbsize = BGP_RX_BUFFER_SIZE; s->rbsize = BGP_RX_BUFFER_SIZE;
s->tbsize = BGP_TX_BUFFER_SIZE; s->tbsize = BGP_TX_BUFFER_SIZE;

View File

@ -703,7 +703,13 @@ sk_setup(sock *s)
if ((s->tos >= 0) && setsockopt(fd, SOL_IP, IP_TOS, &s->tos, sizeof(s->tos)) < 0) if ((s->tos >= 0) && setsockopt(fd, SOL_IP, IP_TOS, &s->tos, sizeof(s->tos)) < 0)
WARN("IP_TOS"); WARN("IP_TOS");
#endif #endif
#ifdef IPV6
int v = 1;
if ((s->flags & SKF_V6ONLY) && setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &v, sizeof(v)) < 0)
WARN("IPV6_V6ONLY");
#endif
if (s->ttl >= 0) if (s->ttl >= 0)
err = sk_set_ttl_int(s); err = sk_set_ttl_int(s);
else else