version 1.1.1.3, 2012/10/09 09:22:28
|
version 1.1.1.4, 2013/07/21 23:54:37
|
Line 149 bgp_update_packet (struct peer *peer, afi_t afi, safi_
|
Line 149 bgp_update_packet (struct peer *peer, afi_t afi, safi_
|
struct bgp_info *binfo = NULL; |
struct bgp_info *binfo = NULL; |
bgp_size_t total_attr_len = 0; |
bgp_size_t total_attr_len = 0; |
unsigned long pos; |
unsigned long pos; |
char buf[BUFSIZ]; |
|
|
|
s = peer->work; |
s = peer->work; |
stream_reset (s); |
stream_reset (s); |
Line 199 bgp_update_packet (struct peer *peer, afi_t afi, safi_
|
Line 198 bgp_update_packet (struct peer *peer, afi_t afi, safi_
|
stream_put_prefix (s, &rn->p); |
stream_put_prefix (s, &rn->p); |
|
|
if (BGP_DEBUG (update, UPDATE_OUT)) |
if (BGP_DEBUG (update, UPDATE_OUT)) |
zlog (peer->log, LOG_DEBUG, "%s send UPDATE %s/%d", | { |
peer->host, | char buf[INET6_BUFSIZ]; |
inet_ntop (rn->p.family, &(rn->p.u.prefix), buf, BUFSIZ), | |
rn->p.prefixlen); | |
|
|
|
zlog (peer->log, LOG_DEBUG, "%s send UPDATE %s/%d", |
|
peer->host, |
|
inet_ntop (rn->p.family, &(rn->p.u.prefix), buf, INET6_BUFSIZ), |
|
rn->p.prefixlen); |
|
} |
|
|
/* Synchnorize attribute. */ |
/* Synchnorize attribute. */ |
if (adj->attr) |
if (adj->attr) |
bgp_attr_unintern (&adj->attr); |
bgp_attr_unintern (&adj->attr); |
Line 285 bgp_withdraw_packet (struct peer *peer, afi_t afi, saf
|
Line 288 bgp_withdraw_packet (struct peer *peer, afi_t afi, saf
|
unsigned long pos; |
unsigned long pos; |
bgp_size_t unfeasible_len; |
bgp_size_t unfeasible_len; |
bgp_size_t total_attr_len; |
bgp_size_t total_attr_len; |
char buf[BUFSIZ]; |
|
|
|
s = peer->work; |
s = peer->work; |
stream_reset (s); |
stream_reset (s); |
Line 324 bgp_withdraw_packet (struct peer *peer, afi_t afi, saf
|
Line 326 bgp_withdraw_packet (struct peer *peer, afi_t afi, saf
|
} |
} |
|
|
if (BGP_DEBUG (update, UPDATE_OUT)) |
if (BGP_DEBUG (update, UPDATE_OUT)) |
zlog (peer->log, LOG_DEBUG, "%s send UPDATE %s/%d -- unreachable", | { |
peer->host, | char buf[INET6_BUFSIZ]; |
inet_ntop (rn->p.family, &(rn->p.u.prefix), buf, BUFSIZ), | |
rn->p.prefixlen); | |
|
|
|
zlog (peer->log, LOG_DEBUG, "%s send UPDATE %s/%d -- unreachable", |
|
peer->host, |
|
inet_ntop (rn->p.family, &(rn->p.u.prefix), buf, INET6_BUFSIZ), |
|
rn->p.prefixlen); |
|
} |
|
|
peer->scount[afi][safi]--; |
peer->scount[afi][safi]--; |
|
|
bgp_adj_out_remove (rn, adj, peer, afi, safi); |
bgp_adj_out_remove (rn, adj, peer, afi, safi); |
Line 366 bgp_default_update_send (struct peer *peer, struct att
|
Line 372 bgp_default_update_send (struct peer *peer, struct att
|
struct prefix p; |
struct prefix p; |
unsigned long pos; |
unsigned long pos; |
bgp_size_t total_attr_len; |
bgp_size_t total_attr_len; |
char attrstr[BUFSIZ]; |
|
char buf[BUFSIZ]; |
|
|
|
if (DISABLE_BGP_ANNOUNCE) |
if (DISABLE_BGP_ANNOUNCE) |
return; |
return; |
Line 382 bgp_default_update_send (struct peer *peer, struct att
|
Line 386 bgp_default_update_send (struct peer *peer, struct att
|
/* Logging the attribute. */ |
/* Logging the attribute. */ |
if (BGP_DEBUG (update, UPDATE_OUT)) |
if (BGP_DEBUG (update, UPDATE_OUT)) |
{ |
{ |
|
char attrstr[BUFSIZ]; |
|
char buf[INET6_BUFSIZ]; |
|
attrstr[0] = '\0'; |
|
|
bgp_dump_attr (peer, attr, attrstr, BUFSIZ); |
bgp_dump_attr (peer, attr, attrstr, BUFSIZ); |
zlog (peer->log, LOG_DEBUG, "%s send UPDATE %s/%d %s", |
zlog (peer->log, LOG_DEBUG, "%s send UPDATE %s/%d %s", |
peer->host, inet_ntop(p.family, &(p.u.prefix), buf, BUFSIZ), | peer->host, inet_ntop(p.family, &(p.u.prefix), buf, INET6_BUFSIZ), |
p.prefixlen, attrstr); |
p.prefixlen, attrstr); |
} |
} |
|
|
Line 435 bgp_default_withdraw_send (struct peer *peer, afi_t af
|
Line 443 bgp_default_withdraw_send (struct peer *peer, afi_t af
|
unsigned long cp; |
unsigned long cp; |
bgp_size_t unfeasible_len; |
bgp_size_t unfeasible_len; |
bgp_size_t total_attr_len; |
bgp_size_t total_attr_len; |
char buf[BUFSIZ]; |
|
|
|
if (DISABLE_BGP_ANNOUNCE) |
if (DISABLE_BGP_ANNOUNCE) |
return; |
return; |
Line 451 bgp_default_withdraw_send (struct peer *peer, afi_t af
|
Line 458 bgp_default_withdraw_send (struct peer *peer, afi_t af
|
pos = 0; |
pos = 0; |
|
|
if (BGP_DEBUG (update, UPDATE_OUT)) |
if (BGP_DEBUG (update, UPDATE_OUT)) |
zlog (peer->log, LOG_DEBUG, "%s send UPDATE %s/%d -- unreachable", | { |
peer->host, inet_ntop(p.family, &(p.u.prefix), buf, BUFSIZ), | char buf[INET6_BUFSIZ]; |
p.prefixlen); | |
|
|
|
zlog (peer->log, LOG_DEBUG, "%s send UPDATE %s/%d -- unreachable", |
|
peer->host, inet_ntop(p.family, &(p.u.prefix), buf, INET6_BUFSIZ), |
|
p.prefixlen); |
|
} |
|
|
s = stream_new (BGP_MAX_PACKET_SIZE); |
s = stream_new (BGP_MAX_PACKET_SIZE); |
|
|
/* Make BGP update packet. */ |
/* Make BGP update packet. */ |
Line 666 bgp_write (struct thread *thread)
|
Line 677 bgp_write (struct thread *thread)
|
|
|
/* Flush any existing events */ |
/* Flush any existing events */ |
BGP_EVENT_ADD (peer, BGP_Stop); |
BGP_EVENT_ADD (peer, BGP_Stop); |
return 0; | goto done; |
| |
case BGP_MSG_KEEPALIVE: |
case BGP_MSG_KEEPALIVE: |
peer->keepalive_out++; |
peer->keepalive_out++; |
break; |
break; |
Line 687 bgp_write (struct thread *thread)
|
Line 699 bgp_write (struct thread *thread)
|
|
|
if (bgp_write_proceed (peer)) |
if (bgp_write_proceed (peer)) |
BGP_WRITE_ON (peer->t_write, bgp_write, peer->fd); |
BGP_WRITE_ON (peer->t_write, bgp_write, peer->fd); |
else | |
sockopt_cork (peer->fd, 0); | done: |
| sockopt_cork (peer->fd, 0); |
return 0; |
return 0; |
} |
} |
|
|
Line 711 bgp_write_notify (struct peer *peer)
|
Line 723 bgp_write_notify (struct peer *peer)
|
val = fcntl (peer->fd, F_GETFL, 0); |
val = fcntl (peer->fd, F_GETFL, 0); |
fcntl (peer->fd, F_SETFL, val & ~O_NONBLOCK); |
fcntl (peer->fd, F_SETFL, val & ~O_NONBLOCK); |
|
|
ret = writen (peer->fd, STREAM_DATA (s), stream_get_endp (s)); | /* Stop collecting data within the socket */ |
| sockopt_cork (peer->fd, 0); |
| |
| ret = write (peer->fd, STREAM_DATA (s), stream_get_endp (s)); |
if (ret <= 0) |
if (ret <= 0) |
{ |
{ |
BGP_EVENT_ADD (peer, TCP_fatal_error); |
BGP_EVENT_ADD (peer, TCP_fatal_error); |
return 0; |
return 0; |
} |
} |
|
|
|
/* Disable Nagle, make NOTIFY packet go out right away */ |
|
val = 1; |
|
(void) setsockopt (peer->fd, IPPROTO_TCP, TCP_NODELAY, |
|
(char *) &val, sizeof (val)); |
|
|
/* Retrieve BGP packet type. */ |
/* Retrieve BGP packet type. */ |
stream_set_getp (s, BGP_MARKER_SIZE + 2); |
stream_set_getp (s, BGP_MARKER_SIZE + 2); |
type = stream_getc (s); |
type = stream_getc (s); |
Line 1400 bgp_open_receive (struct peer *peer, bgp_size_t size)
|
Line 1420 bgp_open_receive (struct peer *peer, bgp_size_t size)
|
/* Peer BGP version check. */ |
/* Peer BGP version check. */ |
if (version != BGP_VERSION_4) |
if (version != BGP_VERSION_4) |
{ |
{ |
u_int8_t maxver = BGP_VERSION_4; | u_int16_t maxver = htons(BGP_VERSION_4); |
| /* XXX this reply may not be correct if version < 4 XXX */ |
if (BGP_DEBUG (normal, NORMAL)) |
if (BGP_DEBUG (normal, NORMAL)) |
zlog_debug ("%s bad protocol version, remote requested %d, local request %d", |
zlog_debug ("%s bad protocol version, remote requested %d, local request %d", |
peer->host, version, BGP_VERSION_4); |
peer->host, version, BGP_VERSION_4); |
|
/* Data must be in network byte order here */ |
bgp_notify_send_with_data (peer, |
bgp_notify_send_with_data (peer, |
BGP_NOTIFY_OPEN_ERR, |
BGP_NOTIFY_OPEN_ERR, |
BGP_NOTIFY_OPEN_UNSUP_VERSION, |
BGP_NOTIFY_OPEN_UNSUP_VERSION, |
&maxver, 1); | (u_int8_t *) &maxver, 2); |
return -1; |
return -1; |
} |
} |
|
|
Line 1508 bgp_update_receive (struct peer *peer, bgp_size_t size
|
Line 1530 bgp_update_receive (struct peer *peer, bgp_size_t size
|
u_char *end; |
u_char *end; |
struct stream *s; |
struct stream *s; |
struct attr attr; |
struct attr attr; |
|
struct attr_extra extra; |
bgp_size_t attribute_len; |
bgp_size_t attribute_len; |
bgp_size_t update_len; |
bgp_size_t update_len; |
bgp_size_t withdraw_len; |
bgp_size_t withdraw_len; |
Line 1515 bgp_update_receive (struct peer *peer, bgp_size_t size
|
Line 1538 bgp_update_receive (struct peer *peer, bgp_size_t size
|
struct bgp_nlri withdraw; |
struct bgp_nlri withdraw; |
struct bgp_nlri mp_update; |
struct bgp_nlri mp_update; |
struct bgp_nlri mp_withdraw; |
struct bgp_nlri mp_withdraw; |
char attrstr[BUFSIZ] = ""; |
|
|
|
/* Status must be Established. */ |
/* Status must be Established. */ |
if (peer->status != Established) |
if (peer->status != Established) |
Line 1528 bgp_update_receive (struct peer *peer, bgp_size_t size
|
Line 1550 bgp_update_receive (struct peer *peer, bgp_size_t size
|
|
|
/* Set initial values. */ |
/* Set initial values. */ |
memset (&attr, 0, sizeof (struct attr)); |
memset (&attr, 0, sizeof (struct attr)); |
|
memset (&extra, 0, sizeof (struct attr_extra)); |
memset (&update, 0, sizeof (struct bgp_nlri)); |
memset (&update, 0, sizeof (struct bgp_nlri)); |
memset (&withdraw, 0, sizeof (struct bgp_nlri)); |
memset (&withdraw, 0, sizeof (struct bgp_nlri)); |
memset (&mp_update, 0, sizeof (struct bgp_nlri)); |
memset (&mp_update, 0, sizeof (struct bgp_nlri)); |
memset (&mp_withdraw, 0, sizeof (struct bgp_nlri)); |
memset (&mp_withdraw, 0, sizeof (struct bgp_nlri)); |
|
attr.extra = &extra; |
|
|
s = peer->ibuf; |
s = peer->ibuf; |
end = stream_pnt (s) + size; |
end = stream_pnt (s) + size; |
Line 1632 bgp_update_receive (struct peer *peer, bgp_size_t size
|
Line 1656 bgp_update_receive (struct peer *peer, bgp_size_t size
|
if (attr_parse_ret == BGP_ATTR_PARSE_WITHDRAW |
if (attr_parse_ret == BGP_ATTR_PARSE_WITHDRAW |
|| BGP_DEBUG (update, UPDATE_IN)) |
|| BGP_DEBUG (update, UPDATE_IN)) |
{ |
{ |
|
char attrstr[BUFSIZ]; |
|
attrstr[0] = '\0'; |
|
|
ret= bgp_dump_attr (peer, &attr, attrstr, BUFSIZ); |
ret= bgp_dump_attr (peer, &attr, attrstr, BUFSIZ); |
int lvl = (attr_parse_ret == BGP_ATTR_PARSE_WITHDRAW) |
int lvl = (attr_parse_ret == BGP_ATTR_PARSE_WITHDRAW) |
? LOG_ERR : LOG_DEBUG; |
? LOG_ERR : LOG_DEBUG; |
Line 1656 bgp_update_receive (struct peer *peer, bgp_size_t size
|
Line 1683 bgp_update_receive (struct peer *peer, bgp_size_t size
|
if (ret < 0) |
if (ret < 0) |
{ |
{ |
bgp_attr_unintern_sub (&attr); |
bgp_attr_unintern_sub (&attr); |
if (attr.extra) |
|
bgp_attr_extra_free (&attr); |
|
return -1; |
return -1; |
} |
} |
|
|
Line 1684 bgp_update_receive (struct peer *peer, bgp_size_t size
|
Line 1709 bgp_update_receive (struct peer *peer, bgp_size_t size
|
if (ret < 0) |
if (ret < 0) |
{ |
{ |
bgp_attr_unintern_sub (&attr); |
bgp_attr_unintern_sub (&attr); |
if (attr.extra) |
|
bgp_attr_extra_free (&attr); |
|
return -1; |
return -1; |
} |
} |
|
|
Line 1832 bgp_update_receive (struct peer *peer, bgp_size_t size
|
Line 1855 bgp_update_receive (struct peer *peer, bgp_size_t size
|
/* Everything is done. We unintern temporary structures which |
/* Everything is done. We unintern temporary structures which |
interned in bgp_attr_parse(). */ |
interned in bgp_attr_parse(). */ |
bgp_attr_unintern_sub (&attr); |
bgp_attr_unintern_sub (&attr); |
if (attr.extra) | |
bgp_attr_extra_free (&attr); | |
| |
/* If peering is stopped due to some reason, do not generate BGP |
/* If peering is stopped due to some reason, do not generate BGP |
event. */ |
event. */ |
if (peer->status != Established) |
if (peer->status != Established) |
Line 1844 bgp_update_receive (struct peer *peer, bgp_size_t size
|
Line 1865 bgp_update_receive (struct peer *peer, bgp_size_t size
|
peer->update_in++; |
peer->update_in++; |
peer->update_time = bgp_clock (); |
peer->update_time = bgp_clock (); |
|
|
/* Generate BGP event. */ | /* Rearm holdtime timer */ |
BGP_EVENT_ADD (peer, Receive_UPDATE_message); | BGP_TIMER_OFF (peer->t_holdtime); |
| bgp_timer_set (peer); |
|
|
return 0; |
return 0; |
} |
} |
Line 2027 bgp_route_refresh_receive (struct peer *peer, bgp_size
|
Line 2049 bgp_route_refresh_receive (struct peer *peer, bgp_size
|
u_int32_t seq; |
u_int32_t seq; |
int psize; |
int psize; |
char name[BUFSIZ]; |
char name[BUFSIZ]; |
char buf[BUFSIZ]; |
|
int ret; |
int ret; |
|
|
if (BGP_DEBUG (normal, NORMAL)) |
if (BGP_DEBUG (normal, NORMAL)) |
Line 2097 bgp_route_refresh_receive (struct peer *peer, bgp_size
|
Line 2118 bgp_route_refresh_receive (struct peer *peer, bgp_size
|
p_pnt += psize; |
p_pnt += psize; |
|
|
if (BGP_DEBUG (normal, NORMAL)) |
if (BGP_DEBUG (normal, NORMAL)) |
zlog_debug ("%s rcvd %s %s seq %u %s/%d ge %d le %d%s", | { |
peer->host, | char buf[INET6_BUFSIZ]; |
(common & ORF_COMMON_PART_REMOVE ? "Remove" : "Add"), | |
(common & ORF_COMMON_PART_DENY ? "deny" : "permit"), | zlog_debug ("%s rcvd %s %s seq %u %s/%d ge %d le %d%s", |
orfp.seq, | peer->host, |
inet_ntop (orfp.p.family, &orfp.p.u.prefix, buf, BUFSIZ), | (common & ORF_COMMON_PART_REMOVE ? "Remove" : "Add"), |
orfp.p.prefixlen, orfp.ge, orfp.le, | (common & ORF_COMMON_PART_DENY ? "deny" : "permit"), |
ok ? "" : " MALFORMED"); | orfp.seq, |
| inet_ntop (orfp.p.family, &orfp.p.u.prefix, buf, INET6_BUFSIZ), |
| orfp.p.prefixlen, orfp.ge, orfp.le, |
| ok ? "" : " MALFORMED"); |
| } |
| |
if (ok) |
if (ok) |
ret = prefix_bgp_orf_set (name, afi, &orfp, |
ret = prefix_bgp_orf_set (name, afi, &orfp, |
(common & ORF_COMMON_PART_DENY ? 0 : 1 ), |
(common & ORF_COMMON_PART_DENY ? 0 : 1 ), |
Line 2369 bgp_marker_all_one (struct stream *s, int length)
|
Line 2394 bgp_marker_all_one (struct stream *s, int length)
|
return 1; |
return 1; |
} |
} |
|
|
|
/* Recent thread time. |
|
On same clock base as bgp_clock (MONOTONIC) |
|
but can be time of last context switch to bgp_read thread. */ |
|
static time_t |
|
bgp_recent_clock (void) |
|
{ |
|
return recent_relative_time().tv_sec; |
|
} |
|
|
/* Starting point of packet process function. */ |
/* Starting point of packet process function. */ |
int |
int |
bgp_read (struct thread *thread) |
bgp_read (struct thread *thread) |
Line 2497 bgp_read (struct thread *thread)
|
Line 2531 bgp_read (struct thread *thread)
|
bgp_open_receive (peer, size); /* XXX return value ignored! */ |
bgp_open_receive (peer, size); /* XXX return value ignored! */ |
break; |
break; |
case BGP_MSG_UPDATE: |
case BGP_MSG_UPDATE: |
peer->readtime = time(NULL); /* Last read timer reset */ | peer->readtime = bgp_recent_clock (); |
bgp_update_receive (peer, size); |
bgp_update_receive (peer, size); |
break; |
break; |
case BGP_MSG_NOTIFY: |
case BGP_MSG_NOTIFY: |
bgp_notify_receive (peer, size); |
bgp_notify_receive (peer, size); |
break; |
break; |
case BGP_MSG_KEEPALIVE: |
case BGP_MSG_KEEPALIVE: |
peer->readtime = time(NULL); /* Last read timer reset */ | peer->readtime = bgp_recent_clock (); |
bgp_keepalive_receive (peer, size); |
bgp_keepalive_receive (peer, size); |
break; |
break; |
case BGP_MSG_ROUTE_REFRESH_NEW: |
case BGP_MSG_ROUTE_REFRESH_NEW: |