Author: adrian.chadd
Date: Mon Feb 23 22:43:08 2009
New Revision: 13856

Modified:
    playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_core.c
    playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_packet.c
    playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_packet.h

Log:
Begin the prep work to separate out packet and FSM related 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  Mon Feb 23 22:43:08 2009
@@ -80,6 +80,41 @@
        bi->state = BGP_OPENCONFIRM;
  }

+static int
+bgp_handle_message(bgp_instance_t *bi, 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);
+        debug(85, 2) ("bgp_decode_message: type %d; len %d\n", type,  
pkt_len);
+        switch  (type) {
+                case 1:         /* OPEN */
+                        r = bgp_handle_open(bi, fd, buf + 19, pkt_len -  
19);
+                        break;
+                case 2:         /* UPDATE */
+                        r = bgp_handle_update(bi, fd, buf + 19, pkt_len -  
19);
+                        break;
+                case 3:         /* NOTIFICATION */
+                        r = bgp_handle_notification(bi, fd, buf + 19,  
pkt_len - 19);
+                        break;
+                case 4:         /* KEEPALIVE */
+                        r = bgp_handle_keepalive(fd, buf + 19, pkt_len -  
19);
+                        break;
+                default:
+                        debug(85, 2) ("bgp_decode_message: unknown message  
type: %d\n", type);
+                        exit(1);
+        }
+
+        return pkt_len;
+}
+
+
  /*
   * Read some data from the given file descriptor (using the read() syscall  
for now!)
   * and update the BGP state machine. The caller should check for retval <=  
0 and reset
@@ -109,7 +144,7 @@
                        debug(85, 5) ("main: incomplete packet\n");
                        break;
                }
-               r = bgp_decode_message(bi, fd, bi->recv.buf + i, 
bi->recv.bufofs - i);
+               r = bgp_handle_message(bi, fd, bi->recv.buf + i, 
bi->recv.bufofs - i);
                assert(r > 0);
                i += r;
                debug(85, 5) ("main: pkt was %d bytes, i is now %d\n", r, i);

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        Mon Feb 23 22:43:08 2009
@@ -376,6 +376,16 @@
        return 1;
  }

+void
+bgp_free_update(bgp_instance_t *bi, bgp_update_state_t *us)
+{
+       safe_free(us->withdraw);
+       safe_free(us->withdraw_mask);
+       safe_free(us->nlri);
+       safe_free(us->nlri_mask);
+       safe_free(us->aspaths);
+}
+
  int
  bgp_handle_update(bgp_instance_t *bi, int fd, const char *buf, int len)
  {
@@ -414,11 +424,7 @@
        rc = 1;
  finish:
        /* free said saved info */
-       safe_free(us.withdraw);
-       safe_free(us.withdraw_mask);
-       safe_free(us.nlri);
-       safe_free(us.nlri_mask);
-       safe_free(us.aspaths);
+       bgp_free_update(bi, &us);

        return rc;
  }
@@ -428,38 +434,4 @@
  {
        debug(85, 2) ("bgp_handle_keepalive: KEEPALIVE RECEIVED\n");
        return 1;
-}
-
-int
-bgp_decode_message(bgp_instance_t *bi, 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);
-       debug(85, 2) ("bgp_decode_message: type %d; len %d\n", type, pkt_len);
-       switch  (type) {
-               case 1:         /* OPEN */
-                       r = bgp_handle_open(bi, fd, buf + 19, pkt_len - 19);
-                       break;
-               case 2:         /* UPDATE */
-                       r = bgp_handle_update(bi, fd, buf + 19, pkt_len - 19);
-                       break;
-               case 3:         /* NOTIFICATION */
-                       r = bgp_handle_notification(bi, fd, buf + 19, pkt_len - 
19);
-                       break;
-               case 4:         /* KEEPALIVE */
-                       r = bgp_handle_keepalive(fd, buf + 19, pkt_len - 19);
-                       break;
-               default:
-                       debug(85, 2) ("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        Mon Feb 23 22:43:08 2009
@@ -9,9 +9,16 @@
  /* XXX eww? */
  struct _bgp_instance;

+/*
+ * XXX can we get away with -not- passing in the bgp_instance here?
+ * XXX now that the RIB related stuff can be done elsewhere?
+ */
  extern int bgp_send_keepalive(struct _bgp_instance *bi, int fd);
  extern int bgp_send_hello(struct _bgp_instance *bi, int fd, unsigned short  
asnum, short hold_time, struct in_addr bgp_id);

-extern int bgp_decode_message(struct _bgp_instance *bi, int fd, const  
const char *buf, int len);
+extern int bgp_handle_open(struct _bgp_instance *bi, int fd, const char  
*buf, int len);
+extern int bgp_handle_update(struct _bgp_instance *bi, int fd, const char  
*buf, int len);
+extern int bgp_handle_notification(struct _bgp_instance *bi, int fd, const  
char *buf, int len);
+extern int bgp_handle_keepalive(int fd, 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to