Author: adrian.chadd
Date: Sun Feb 22 12:33:00 2009
New Revision: 13818
Modified:
playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_core.c
playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_core.h
playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_packet.c
playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_packet.h
Log:
General code reorganisation; prepare for actual FSM-y stuff.
Modified: playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_core.c
==============================================================================
--- playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_core.c (original)
+++ playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_core.c Sun Feb 22 12:33:00 2009
@@ -13,385 +13,13 @@
#include "../libcore/tools.h"
#include "../libsqdebug/debug.h"
-int
-bgp_msg_len(const char *buf, int len)
-{
- u_int16_t msg_len;
+#include "../libsqinet/sqinet.h"
- if (len < 19)
- return -1;
- msg_len = ntohs(* (u_int16_t *) (buf + 16));
- return msg_len;
-}
+#include "bgp_packet.h"
+#include "bgp_rib.h"
+#include "bgp_core.h"
-int
-bgp_msg_type(const char *buf, int len)
-{
- u_int8_t type;
-
- if (len < 19)
- return -1;
-
- type = * (u_int8_t *) (buf + 18);
- return type;
-}
-
-int
-bgp_msg_isvalid(const char *buf, int len)
-{
- return -1;
-}
-
-int
-bgp_msg_complete(const char *buf, int len)
-{
- int type;
- int msg_len;
-
- type = bgp_msg_type(buf, len);
- msg_len = bgp_msg_len(buf, len);
- //printf("bgp_msg_complete: type %d, pktlen %d, msglen %d\n", type,
len,
msg_len);
-
- if (type < 0)
- return 0;
- if (msg_len > len)
- return 0;
- return 1;
-}
-
-/*
- * XXX absolutely hacky!
- */
-int
-bgp_send_hello(int fd, unsigned short asnum, short hold_time, struct
in_addr bgp_id)
-{
- char send_buf[128];
- char *p = send_buf;
- u_int16_t t;
- u_int16_t len;
- u_int8_t t8;
- int pkt_len;
-
- /* marker */
- memset(p, 255, 16);
- p += 16;
-
- /* length - fill out later! */
- p += 2;
-
- /* type */
- t8 = 1; /* open message */
- memcpy(p, &t8, sizeof(t8));
- p += 1;
-
- /* now, hello */
- t8 = 4; /* bgp4 */
- memcpy(p, &t8, sizeof(t8));
- p += 1;
-
- /* as number */
- t = htons(asnum);
- memcpy(p, &t, sizeof(t));
- p += 2;
-
- /* hold time */
- t = htons(hold_time);
- memcpy(p, &t, sizeof(t));
- p += 2;
-
- /* bgp identifier */
- memcpy(p, &bgp_id.s_addr, sizeof(bgp_id.s_addr));
- p += 4;
-
- /* optional parameter */
- t8 = 0;
- memcpy(p, &t8, sizeof(t8));
- p += 1;
-
- pkt_len = p - send_buf;
- printf("OPEN: len: %d\n", pkt_len);
- len = htons(p - send_buf);
- p = send_buf + 16;
- memcpy(p, &len, sizeof(len));
-
- return (write(fd, send_buf, pkt_len) == pkt_len);
-}
-
-int
-bgp_send_keepalive(int fd)
-{
- char send_buf[128];
- char *p = send_buf;
- u_int8_t t8;
- int pkt_len;
- u_int16_t len;
-
- /* marker */
- memset(p, 255, 16);
- p += 16;
-
- /* length - fill out later! */
- p += 2;
-
- /* type */
- t8 = 4; /* open message */
- memcpy(p, &t8, sizeof(t8));
- p += 1;
-
- pkt_len = p - send_buf;
- //printf("bgp_send_keepalive: KEEPALIVE: len: %d\n", pkt_len);
- len = htons(p - send_buf);
- p = send_buf + 16;
- memcpy(p, &len, sizeof(len));
-
- return (write(fd, send_buf, pkt_len) == pkt_len);
-
-
-}
-
-int
-bgp_handle_notification(int fd, const char *buf, int len)
-{
- u_int8_t err_code;
- u_int8_t err_subcode;
- u_int16_t err_data;
-
- err_code = * (u_int8_t *) buf;
- err_subcode = * (u_int8_t *) (buf + 2);
- err_data = ntohs(* (u_int8_t *) (buf + 4));
- printf("bgp_handle_notification: err %d, subcode %d, data %d\n",
err_code, err_subcode, err_data);
- return 1;
-}
-
-int
-bgp_handle_open(int fd, const char *buf, int len)
-{
- u_int8_t version;
- u_int16_t bgp_as;
- u_int16_t hold_timer;
- struct in_addr bgp_id;
- int parm_len;
-
- /* XXX should ensure we have enough space! */
-
- version = * (u_int8_t *) buf;
- bgp_as = ntohs(* (u_int16_t *) (buf + 1));
- hold_timer = ntohs(* (u_int16_t *) (buf + 3));
- memcpy(&bgp_id, buf + 5, 4);
-
- parm_len = * (u_int8_t *) (buf + 9);
- /* XXX don't bother decoding the OPEN parameters for now! */
-
- //printf("bgp_handle_open: got version %d, AS %d, timer %d,
parm_len %d\n", version, bgp_as, hold_timer, parm_len);
-
- /* Queue a keepalive message */
- bgp_send_keepalive(fd);
-
- return 1;
-}
-
-int
-bgp_handle_update_withdraw(const char *buf, int len)
-{
- struct in_addr pf;
- u_int8_t pl, netmask;
- int i = 0;
-
- if (len == 0)
- return 1;
-
- printf(" bgp_handle_update_withdraw: len %d\n", len);
- while (i < len) {
- bzero(&pf, sizeof(pf));
- /* The "length" is the number of bits which are "valid" .. */
- netmask = (* (u_int8_t *) (buf + i));
- if (netmask == 0)
- pl = 0;
- else
- pl = ((netmask - 1) / 8) + 1;
- i++;
- printf(" bgp_handle_update_withdraw: netmask %d; len %d\n",
netmask,
pl);
- /* XXX bounds check? */
- memcpy(&pf, buf + i, pl);
- printf(" bgp_handle_update_withdraw: prefix %s/%d\n",
inet_ntoa(pf),
netmask);
- i += pl;
- }
- return 1;
-}
-
-int
-bgp_handle_update_pathattrib_origin(const char *buf, int len)
-{
- u_int8_t origin;
- if (len < 1)
- return 0;
- origin = * (u_int8_t *) buf;
- printf(" bgp_handle_update_pathattrib_origin: origin id %d\n", origin);
- return 1;
-}
-
-int
-bgp_handle_update_pathattrib_aspath(const char *buf, int len)
-{
- int i;
- u_int16_t aspath_entry;
- u_int8_t aspath_type, aspath_len;
-
- if (len < 2)
- return 0;
-
- aspath_type = * (u_int8_t *) (buf);
- aspath_len = * (u_int8_t *) (buf + 1);
-
- /* XXX well, the length should be verified / used / bounds checked? */
-
- printf(" bgp_handle_update_pathattrib_aspath:");
- for (i = 2; i < len; i += 2) {
- aspath_entry = ntohs(* (u_int16_t *) (buf + i));
- printf(" %d", aspath_entry);
- }
- printf("\n");
-
- return 1;
-}
-
-int
-bgp_handle_update_pathattrib(const char *buf, int len)
-{
- int i = 0;
- u_int8_t a_flags, a_type;
- int a_len;
-
- /* Iterate over the buffer, pulling out <type, length, value> fields */
- /* XXX should bounds check some more! */
- //printf("bgp_handle_update_pathattrib: BEGIN\n");
- while (i < len) {
- a_flags = * (u_int8_t *) (buf + i);
- a_type = * (u_int8_t *) (buf + i + 1);
- i += 2;
- /* Length is either 8 or 16 bits; encoded by the extended
length bit */
- if (a_flags & 0x10) {
- a_len = ntohs(* (u_int16_t *) (buf + i));
- i += 2;
- } else {
- a_len = * (u_int8_t *) (buf + i);
- i += 1;
- }
- //printf(" bgp_handle_update_pathattrib: flags %x, type %x,
len %d\n",
a_flags, a_type, a_len);
-
- switch (a_type) {
- case 1: /* origin */
- if (bgp_handle_update_pathattrib_origin(buf +
i, a_len) < 0)
- return 0;
- break;
- case 2: /* as path */
- if (bgp_handle_update_pathattrib_aspath(buf +
i, a_len) < 0)
- return 0;
- break;
- default:
- //printf(" bgp_handle_path_attrib: don't know
type %d\n", a_type);
- break;
- }
-
- i += a_len;
- }
- //printf("bgp_handle_update_pathattrib: DONE\n");
- return 1;
-}
-
-int
-bgp_handle_update_nlri(const char *buf, int len)
-{
- struct in_addr pf;
- u_int8_t pl, netmask;
- int i = 0;
-
- if (len == 0)
- return 1;
-
- printf(" bgp_handle_update_nlri: len %d\n", len);
- while (i < len) {
- bzero(&pf, sizeof(pf));
- /* The "length" is the number of bits which are "valid" .. */
- netmask = (* (u_int8_t *) (buf + i));
- if (netmask == 0)
- pl = 0;
- else
- pl = ((netmask - 1) / 8) + 1;
- i++;
- printf(" bgp_handle_update_nlri: netmask %d; len %d\n",
netmask, pl);
- /* XXX bounds check? */
- memcpy(&pf, buf + i, pl);
- printf(" bgp_handle_update_nlri: prefix %s/%d\n",
inet_ntoa(pf),
netmask);
- i += pl;
- }
- return 1;
-}
-
-int
-bgp_handle_update(int fd, const char *buf, int len)
-{
- u_int16_t withdraw_route_len;
- u_int16_t path_attrib_len;
-
- withdraw_route_len = ntohs(* (u_int16_t *) buf);
- path_attrib_len = ntohs(* (u_int16_t *) (buf + withdraw_route_len + 2));
-
- printf("bgp_handle_update: UPDATE pktlen %d: withdraw_route_len %d;
path
attrib len %d\n",
- len, withdraw_route_len, path_attrib_len);
-
- if (! bgp_handle_update_withdraw(buf + 2, withdraw_route_len))
- return 0;
- if (! bgp_handle_update_pathattrib(buf + 2 + withdraw_route_len + 2,
path_attrib_len))
- return 0;
- /* XXX need to calculate the length and offset correctly! */
- if (! bgp_handle_update_nlri(buf + 2 + withdraw_route_len + 2 +
path_attrib_len, len - (2 + withdraw_route_len + 2 + path_attrib_len)))
- return 0;
-
- return 1;
-}
-
-int
-bgp_handle_keepalive(int fd, const char *buf, int len)
-{
- //printf("bgp_handle_keepalive: KEEPALIVE RECEIVED\n");
- return 1;
-}
-
-int
-bgp_decode_message(int fd, const const char *buf, int len)
-{
- int r;
-
- u_int8_t type;
- u_int16_t pkt_len;
- /* XXX should check the marker is 16 bytes */
- /* XXX should make sure there's enough bytes in the msg! */
-
- pkt_len = ntohs(* (u_int16_t *) (buf + 16));
- type = * (u_int8_t *) (buf + 18);
- //printf("bgp_decode_message: type %d; len %d\n", type, pkt_len);
- switch (type) {
- case 1: /* OPEN */
- r = bgp_handle_open(fd, buf + 19, pkt_len - 19);
- break;
- case 2: /* UPDATE */
- r = bgp_handle_update(fd, buf + 19, pkt_len - 19);
- break;
- case 3: /* NOTIFICATION */
- r = bgp_handle_notification(fd, buf + 19, pkt_len - 19);
- break;
- case 4: /* KEEPALIVE */
- r = bgp_handle_keepalive(fd, buf + 19, pkt_len - 19);
- break;
- default:
- printf("bgp_decode_message: unknown message type:
%d\n", type);
- exit(1);
- }
-
- return pkt_len;
-}
#if 0
int
Modified: playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_core.h
==============================================================================
--- playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_core.h (original)
+++ playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_core.h Sun Feb 22 12:33:00 2009
@@ -1,5 +1,31 @@
#ifndef __LIBSQBGP_BGP_CORE_H__
#define __LIBSQBGP_BGP_CORE_H__
+#define BGP_RECV_BUF 4096
+
+struct _bgp_instance {
+ struct {
+ char buf[BGP_RECV_BUF];
+ int offset;
+ } recv;
+
+ u_short hold_time; /* Calculated from local and remote
hold times */
+
+ struct {
+ u_short asn;
+ u_short hold_time;
+ sqaddr_t addr;
+ } lcl, rem;
+
+ /* The AS path table */
+
+ /* The RIB */
+};
+
+typedef struct _bgp_instance bgp_instance_t;
+
+void bgp_create_instance(bgp_instance_t *bi);
+void bgp_destroy_instance(bgp_instance_t *bi);
+
#endif
Modified: playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_packet.c
==============================================================================
--- playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_packet.c (original)
+++ playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_packet.c Sun Feb 22 12:33:00 2009
@@ -0,0 +1,401 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include "../include/util.h"
+#include "../libcore/tools.h"
+#include "../libsqdebug/debug.h"
+
+#include "../libsqinet/sqinet.h"
+
+
+#include "bgp_packet.h"
+#include "bgp_rib.h"
+#include "bgp_core.h"
+
+int
+bgp_msg_len(const char *buf, int len)
+{
+ u_int16_t msg_len;
+
+ if (len < 19)
+ return -1;
+
+ msg_len = ntohs(* (u_int16_t *) (buf + 16));
+ return msg_len;
+}
+
+int
+bgp_msg_type(const char *buf, int len)
+{
+ u_int8_t type;
+
+ if (len < 19)
+ return -1;
+
+ type = * (u_int8_t *) (buf + 18);
+ return type;
+}
+
+int
+bgp_msg_isvalid(const char *buf, int len)
+{
+ return -1;
+}
+
+int
+bgp_msg_complete(const char *buf, int len)
+{
+ int type;
+ int msg_len;
+
+ type = bgp_msg_type(buf, len);
+ msg_len = bgp_msg_len(buf, len);
+ //printf("bgp_msg_complete: type %d, pktlen %d, msglen %d\n", type,
len,
msg_len);
+
+ if (type < 0)
+ return 0;
+ if (msg_len > len)
+ return 0;
+ return 1;
+}
+
+/*
+ * XXX absolutely hacky!
+ */
+int
+bgp_send_hello(int fd, unsigned short asnum, short hold_time, struct
in_addr bgp_id)
+{
+ char send_buf[128];
+ char *p = send_buf;
+ u_int16_t t;
+ u_int16_t len;
+ u_int8_t t8;
+ int pkt_len;
+
+ /* marker */
+ memset(p, 255, 16);
+ p += 16;
+
+ /* length - fill out later! */
+ p += 2;
+
+ /* type */
+ t8 = 1; /* open message */
+ memcpy(p, &t8, sizeof(t8));
+ p += 1;
+
+ /* now, hello */
+ t8 = 4; /* bgp4 */
+ memcpy(p, &t8, sizeof(t8));
+ p += 1;
+
+ /* as number */
+ t = htons(asnum);
+ memcpy(p, &t, sizeof(t));
+ p += 2;
+
+ /* hold time */
+ t = htons(hold_time);
+ memcpy(p, &t, sizeof(t));
+ p += 2;
+
+ /* bgp identifier */
+ memcpy(p, &bgp_id.s_addr, sizeof(bgp_id.s_addr));
+ p += 4;
+
+ /* optional parameter */
+ t8 = 0;
+ memcpy(p, &t8, sizeof(t8));
+ p += 1;
+
+ pkt_len = p - send_buf;
+ printf("OPEN: len: %d\n", pkt_len);
+ len = htons(p - send_buf);
+ p = send_buf + 16;
+ memcpy(p, &len, sizeof(len));
+
+ return (write(fd, send_buf, pkt_len) == pkt_len);
+}
+
+int
+bgp_send_keepalive(int fd)
+{
+ char send_buf[128];
+ char *p = send_buf;
+ u_int8_t t8;
+ int pkt_len;
+ u_int16_t len;
+
+ /* marker */
+ memset(p, 255, 16);
+ p += 16;
+
+ /* length - fill out later! */
+ p += 2;
+
+ /* type */
+ t8 = 4; /* open message */
+ memcpy(p, &t8, sizeof(t8));
+ p += 1;
+
+ pkt_len = p - send_buf;
+ //printf("bgp_send_keepalive: KEEPALIVE: len: %d\n", pkt_len);
+ len = htons(p - send_buf);
+ p = send_buf + 16;
+ memcpy(p, &len, sizeof(len));
+
+ return (write(fd, send_buf, pkt_len) == pkt_len);
+
+
+}
+
+int
+bgp_handle_notification(int fd, const char *buf, int len)
+{
+ u_int8_t err_code;
+ u_int8_t err_subcode;
+ u_int16_t err_data;
+
+ err_code = * (u_int8_t *) buf;
+ err_subcode = * (u_int8_t *) (buf + 2);
+ err_data = ntohs(* (u_int8_t *) (buf + 4));
+ printf("bgp_handle_notification: err %d, subcode %d, data %d\n",
err_code, err_subcode, err_data);
+ return 1;
+}
+
+int
+bgp_handle_open(int fd, const char *buf, int len)
+{
+ u_int8_t version;
+ u_int16_t bgp_as;
+ u_int16_t hold_timer;
+ struct in_addr bgp_id;
+ int parm_len;
+
+ /* XXX should ensure we have enough space! */
+
+ version = * (u_int8_t *) buf;
+ bgp_as = ntohs(* (u_int16_t *) (buf + 1));
+ hold_timer = ntohs(* (u_int16_t *) (buf + 3));
+ memcpy(&bgp_id, buf + 5, 4);
+
+ parm_len = * (u_int8_t *) (buf + 9);
+ /* XXX don't bother decoding the OPEN parameters for now! */
+
+ //printf("bgp_handle_open: got version %d, AS %d, timer %d,
parm_len %d\n", version, bgp_as, hold_timer, parm_len);
+
+ /* Queue a keepalive message */
+ bgp_send_keepalive(fd);
+
+ return 1;
+}
+
+int
+bgp_handle_update_withdraw(const char *buf, int len)
+{
+ struct in_addr pf;
+ u_int8_t pl, netmask;
+ int i = 0;
+
+ if (len == 0)
+ return 1;
+
+ printf(" bgp_handle_update_withdraw: len %d\n", len);
+ while (i < len) {
+ bzero(&pf, sizeof(pf));
+ /* The "length" is the number of bits which are "valid" .. */
+ netmask = (* (u_int8_t *) (buf + i));
+ if (netmask == 0)
+ pl = 0;
+ else
+ pl = ((netmask - 1) / 8) + 1;
+ i++;
+ printf(" bgp_handle_update_withdraw: netmask %d; len %d\n",
netmask,
pl);
+ /* XXX bounds check? */
+ memcpy(&pf, buf + i, pl);
+ printf(" bgp_handle_update_withdraw: prefix %s/%d\n",
inet_ntoa(pf),
netmask);
+ i += pl;
+ }
+ return 1;
+}
+
+int
+bgp_handle_update_pathattrib_origin(const char *buf, int len)
+{
+ u_int8_t origin;
+ if (len < 1)
+ return 0;
+ origin = * (u_int8_t *) buf;
+ printf(" bgp_handle_update_pathattrib_origin: origin id %d\n", origin);
+ return 1;
+}
+
+int
+bgp_handle_update_pathattrib_aspath(const char *buf, int len)
+{
+ int i;
+ u_int16_t aspath_entry;
+ u_int8_t aspath_type, aspath_len;
+
+ if (len < 2)
+ return 0;
+
+ aspath_type = * (u_int8_t *) (buf);
+ aspath_len = * (u_int8_t *) (buf + 1);
+
+ /* XXX well, the length should be verified / used / bounds checked? */
+
+ printf(" bgp_handle_update_pathattrib_aspath:");
+ for (i = 2; i < len; i += 2) {
+ aspath_entry = ntohs(* (u_int16_t *) (buf + i));
+ printf(" %d", aspath_entry);
+ }
+ printf("\n");
+
+ return 1;
+}
+
+int
+bgp_handle_update_pathattrib(const char *buf, int len)
+{
+ int i = 0;
+ u_int8_t a_flags, a_type;
+ int a_len;
+
+ /* Iterate over the buffer, pulling out <type, length, value> fields */
+ /* XXX should bounds check some more! */
+ //printf("bgp_handle_update_pathattrib: BEGIN\n");
+ while (i < len) {
+ a_flags = * (u_int8_t *) (buf + i);
+ a_type = * (u_int8_t *) (buf + i + 1);
+ i += 2;
+ /* Length is either 8 or 16 bits; encoded by the extended
length bit */
+ if (a_flags & 0x10) {
+ a_len = ntohs(* (u_int16_t *) (buf + i));
+ i += 2;
+ } else {
+ a_len = * (u_int8_t *) (buf + i);
+ i += 1;
+ }
+ //printf(" bgp_handle_update_pathattrib: flags %x, type %x,
len %d\n",
a_flags, a_type, a_len);
+
+ switch (a_type) {
+ case 1: /* origin */
+ if (bgp_handle_update_pathattrib_origin(buf +
i, a_len) < 0)
+ return 0;
+ break;
+ case 2: /* as path */
+ if (bgp_handle_update_pathattrib_aspath(buf +
i, a_len) < 0)
+ return 0;
+ break;
+ default:
+ //printf(" bgp_handle_path_attrib: don't know
type %d\n", a_type);
+ break;
+ }
+
+ i += a_len;
+ }
+ //printf("bgp_handle_update_pathattrib: DONE\n");
+ return 1;
+}
+
+int
+bgp_handle_update_nlri(const char *buf, int len)
+{
+ struct in_addr pf;
+ u_int8_t pl, netmask;
+ int i = 0;
+
+ if (len == 0)
+ return 1;
+
+ printf(" bgp_handle_update_nlri: len %d\n", len);
+ while (i < len) {
+ bzero(&pf, sizeof(pf));
+ /* The "length" is the number of bits which are "valid" .. */
+ netmask = (* (u_int8_t *) (buf + i));
+ if (netmask == 0)
+ pl = 0;
+ else
+ pl = ((netmask - 1) / 8) + 1;
+ i++;
+ printf(" bgp_handle_update_nlri: netmask %d; len %d\n",
netmask, pl);
+ /* XXX bounds check? */
+ memcpy(&pf, buf + i, pl);
+ printf(" bgp_handle_update_nlri: prefix %s/%d\n",
inet_ntoa(pf),
netmask);
+ i += pl;
+ }
+ return 1;
+}
+
+int
+bgp_handle_update(int fd, const char *buf, int len)
+{
+ u_int16_t withdraw_route_len;
+ u_int16_t path_attrib_len;
+
+ withdraw_route_len = ntohs(* (u_int16_t *) buf);
+ path_attrib_len = ntohs(* (u_int16_t *) (buf + withdraw_route_len + 2));
+
+ printf("bgp_handle_update: UPDATE pktlen %d: withdraw_route_len %d;
path
attrib len %d\n",
+ len, withdraw_route_len, path_attrib_len);
+
+ if (! bgp_handle_update_withdraw(buf + 2, withdraw_route_len))
+ return 0;
+ if (! bgp_handle_update_pathattrib(buf + 2 + withdraw_route_len + 2,
path_attrib_len))
+ return 0;
+ /* XXX need to calculate the length and offset correctly! */
+ if (! bgp_handle_update_nlri(buf + 2 + withdraw_route_len + 2 +
path_attrib_len, len - (2 + withdraw_route_len + 2 + path_attrib_len)))
+ return 0;
+
+ return 1;
+}
+
+int
+bgp_handle_keepalive(int fd, const char *buf, int len)
+{
+ //printf("bgp_handle_keepalive: KEEPALIVE RECEIVED\n");
+ return 1;
+}
+
+int
+bgp_decode_message(int fd, const const char *buf, int len)
+{
+ int r;
+
+ u_int8_t type;
+ u_int16_t pkt_len;
+ /* XXX should check the marker is 16 bytes */
+ /* XXX should make sure there's enough bytes in the msg! */
+
+ pkt_len = ntohs(* (u_int16_t *) (buf + 16));
+ type = * (u_int8_t *) (buf + 18);
+ //printf("bgp_decode_message: type %d; len %d\n", type, pkt_len);
+ switch (type) {
+ case 1: /* OPEN */
+ r = bgp_handle_open(fd, buf + 19, pkt_len - 19);
+ break;
+ case 2: /* UPDATE */
+ r = bgp_handle_update(fd, buf + 19, pkt_len - 19);
+ break;
+ case 3: /* NOTIFICATION */
+ r = bgp_handle_notification(fd, buf + 19, pkt_len - 19);
+ break;
+ case 4: /* KEEPALIVE */
+ r = bgp_handle_keepalive(fd, buf + 19, pkt_len - 19);
+ break;
+ default:
+ printf("bgp_decode_message: unknown message type:
%d\n", type);
+ exit(1);
+ }
+
+ return pkt_len;
+}
Modified: playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_packet.h
==============================================================================
--- playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_packet.h (original)
+++ playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_packet.h Sun Feb 22 12:33:00 2009
@@ -1,5 +1,13 @@
#ifndef __LIBSQBGP_BGP_PACKET_H__
#define __LIBSQBGP_BGP_PACKET_H__
+extern int bgp_msg_len(const char *buf, int len);
+extern int bgp_msg_type(const char *buf, int len);
+extern int bgp_msg_isvalid(const char *buf, int len);
+extern int bgp_msg_complete(const char *buf, int len);
+
+extern int bgp_send_keepalive(int fd);
+
+extern int bgp_decode_message(int fd, const const char *buf, int len);
#endif
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"lusca-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/lusca-commit?hl=en
-~----------~----~----~----~------~----~------~--~---