• R/O
  • SSH
  • HTTPS

提交

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

bmpStation is server of BGP monitoring protocol.


Commit MetaInfo

修订版4 (tree)
时间2015-01-11 14:18:12
作者yuki0220

Log Message

bmpAnalysis can understand update/withdrawn prefix

更改概述

差异

--- trunk/libbgp/getBGPmessages.c (nonexistent)
+++ trunk/libbgp/getBGPmessages.c (revision 4)
@@ -0,0 +1,338 @@
1+/*
2+ * The MIT License
3+ *
4+ * Copyright (c) 2014 Yuki SAKAI
5+ * All Rights Reserved.
6+ *
7+ * Permission is hereby granted, free of charge, to any person obtaining a
8+ * copy of this software and associated documentation files (the "Software"),
9+ * to deal in the Software without restriction, including without limitation
10+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11+ * and/or sell copies of the Software, and to permit persons to whom the
12+ * Software is furnished to do so, subject to the following conditions:
13+ *
14+ * The above copyright notice and this permission notice shall be included in
15+ * all copies or substantial portions of the Software.
16+ *
17+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23+ * IN THE SOFTWARE.
24+ */
25+
26+/*******************************************************************************
27+ * include ********************************************************************/
28+#if !defined(BGP_H__)
29+# include <bgp.h>
30+#endif
31+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
32+#if !defined(_SYS_ENDIAN_H) && !defined(_SYS_ENDIAN_H_)
33+# include <sys/endian.h>
34+#endif
35+#else
36+#if !defined(_ENDIAN_H) && !defined(_ENDIAN_H_)
37+# include <endian.h>
38+#endif
39+#endif
40+
41+
42+static int BGPUpdatePathAttributeMPreachNLRI (u_int8_t *, ssize_t, BGPUpdateInfo *);
43+static int BGPUpdatePathAttributeMPUnreachNLRI (u_int8_t *, ssize_t, BGPUpdateInfo *);
44+/*%''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''%**
45+ *: get BGP Messages process :**
46+ *%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,%*/
47+#define DEBUG 1
48+#if DEBUG == 1
49+static void HEXoutput (u_int8_t *rdata, int len, int max)
50+{
51+ int i;
52+ int outLen;
53+ int counter = -16;
54+ outLen = (len<max?len:max);
55+
56+ printf ("len: %d, output: %d\n", len, outLen);
57+ for (i=0; i<outLen; i++) {
58+ if ((i%16)==0) {counter += 16; printf ("0x%04X:", counter);}
59+ if ((i%2)==0) {printf (" ");}
60+ printf ("%02x", rdata[i]);
61+ if ((i%16)==15) {printf ("\n");}
62+ }
63+ printf ("\n");
64+}
65+#endif
66+
67+/*******************************************************************************
68+ * BGP messages ****************************************************************
69+ *
70+ ******************************************************************************/
71+int BGPupdateMessages (u_int8_t *msg, ssize_t size, BGPUpdateInfo *bgpInfo)
72+{
73+ int i, ret;
74+ ssize_t updateMsgLen, lenNLRI;
75+ BGPCommonHeader *pBGPheader;
76+ BGPUpdateLength *plenWdrawn, *plenPattr, lenWdrawn, lenPattr;
77+ u_int8_t *pProc, *pWdrawn, *pPattr, *pNLRI;
78+ pBGPheader = (BGPCommonHeader *)msg;
79+#if DEBUG == 1 && 0
80+ HEXoutput ((u_int8_t *)msg, size, 256);
81+#endif
82+ if (msg==NULL) {return -1;}
83+ else if (size<sizeof (BGPCommonHeader) ) {return -1;}
84+ else if (size<be16toh (pBGPheader->length)) {return -1;}
85+ else if (pBGPheader->type!=2) {return 0;}
86+ for (i=0; i<4; i++) {if (pBGPheader->Maker[i]!=0xffffffff) {return -1;}}
87+
88+ /*Get Area*******************************************************************/
89+ updateMsgLen = be16toh (pBGPheader->length) - sizeof (BGPCommonHeader);
90+ /* withdrawn area */
91+ pWdrawn = (u_int8_t *)(pBGPheader+1);
92+ lenWdrawn = be16toh (*((BGPUpdateLength *)pWdrawn));
93+ pWdrawn += sizeof (BGPUpdateLength);
94+#if DEBUG == 1 && 0
95+ printf ("withdrawn area: %d\n", lenWdrawn);
96+ HEXoutput ((u_int8_t *)pWdrawn, lenWdrawn, 256);
97+#endif
98+
99+ /* path attribute area */
100+ pPattr = (u_int8_t *)(pWdrawn + lenWdrawn);
101+ lenPattr = be16toh (*((BGPUpdateLength *)pPattr));
102+ pPattr += sizeof (BGPUpdateLength);
103+#if DEBUG == 1 && 0
104+ printf ("path attribute area: %d\n", lenPattr);
105+ HEXoutput ((u_int8_t *)pPattr, lenPattr, 256);
106+#endif
107+
108+ /* NLRI area */
109+ pNLRI = (u_int8_t *)(pPattr + lenPattr);
110+ lenNLRI = updateMsgLen - (sizeof (BGPUpdateLength) * 2 + lenWdrawn + lenPattr);
111+#if DEBUG == 1 && 0
112+ printf ("NLRI area: %d\n", lenNLRI);
113+ HEXoutput ((u_int8_t *)pNLRI, lenNLRI, 256);
114+#endif
115+
116+ /*Check**********************************************************************/
117+ if (lenWdrawn>0) {}
118+ else if (lenPattr >0) {}
119+ else if (lenNLRI >0) {}
120+ else {return -1;}
121+ /*Get BGP Update Infomation**************************************************/
122+ /* withdrawn */
123+ if (lenWdrawn>0) {
124+#if DEBUG == 1 && 0
125+ printf ("wdrawn\n");
126+#endif
127+ bgpInfo->NLRIAFI = 1;
128+ if (!BGPMessagesAddress (pWdrawn, lenWdrawn, &bgpInfo->withdrawnList, &bgpInfo->withdrawnNum)) {return -1;}
129+ }
130+
131+ /* Path attribute */
132+ if (lenPattr>0) {
133+#if DEBUG == 1 && 0
134+ printf ("Path attribute\n");
135+#endif
136+ ret = BGPUpdatePathAttribute (pPattr, lenPattr, bgpInfo);
137+ if (ret==0) {return 0;}
138+ else if (ret< 0) {return -1;}
139+ }
140+
141+ /* NLRI */
142+ if (lenNLRI>0) {
143+#if DEBUG == 1 && 0
144+ printf ("NLRI\n");
145+#endif
146+ bgpInfo->NLRIAFI = 1;
147+ if (!BGPMessagesAddress (pNLRI, lenNLRI, &bgpInfo->NLRIList, &bgpInfo->NLRINum)) {return -1;}
148+ }
149+
150+ return 1;
151+}
152+
153+
154+/*******************************************************************************
155+ * Path attribute process ******************************************************
156+ *
157+ ******************************************************************************/
158+int BGPUpdatePathAttribute (u_int8_t *msg, ssize_t size, BGPUpdateInfo *bgpInfo)
159+{
160+ int ret;
161+ u_int8_t *pProc;
162+ int modlenPathAttr, lenAttr;
163+ ssize_t PathAttrLen, PAHlen;
164+ BGPUpdatePathAttr *pPAttr;
165+
166+ if (msg==NULL) {return -1;}
167+ else if (size<sizeof (BGPUpdatePathAttr)+1) {return -1;}
168+ pProc = msg;
169+ modlenPathAttr = size;
170+ do {
171+#if DEBUG == 1 && 0
172+ printf ("modlenPathAttr: %d\n", modlenPathAttr);
173+#endif
174+ /* header processing */
175+ PAHlen = sizeof (BGPUpdatePathAttr) + 1;
176+ if (modlenPathAttr<PAHlen) {return -1;}
177+ pPAttr = (BGPUpdatePathAttr *)pProc;
178+ if ((pPAttr->attrFlag & 0x80)==0x80) {
179+ /* optional path attribute proc */
180+ }
181+ if ((pPAttr->attrFlag & 0x40)==0x40) {
182+ /* transitive path attribute proc */
183+ }
184+ if ((pPAttr->attrFlag & 0x20)==0x20) {
185+ /* partial path attribute proc */
186+ }
187+ if ((pPAttr->attrFlag & 0x10)==0x10) {
188+ PAHlen++;
189+ if (modlenPathAttr<PAHlen) {return -1;}
190+ lenAttr = be16toh (*(u_int16_t *)(pPAttr+1));
191+ } else {
192+ lenAttr = (int)*(u_int8_t *)(pPAttr+1);
193+ }
194+ if (modlenPathAttr < (PAHlen+lenAttr)) {return -1;}
195+
196+
197+#if DEBUG == 1 && 1
198+ printf ("lenAttr: %d, PAHlen: %d\n", lenAttr, PAHlen);
199+ HEXoutput ((u_int8_t *)pPAttr, (lenAttr + PAHlen), 256);
200+#endif
201+ /* data proc */
202+ switch (pPAttr->attrType) {
203+ case 0: /* reserved */
204+ return -1;
205+ break;
206+#if 0
207+ case 1: /* ORIGIN */
208+ break;
209+ case 2: /* AS_PATH */
210+ break;
211+ case 3: /* NEXT_HOP */
212+ break;
213+#endif
214+ case 14: /* MP_REACH_NLRI */
215+ ret = BGPUpdatePathAttributeMPreachNLRI ((pProc + PAHlen), lenAttr, bgpInfo);
216+ break;
217+ case 15: /* MP_UNREACH_NLRI */
218+ ret = BGPUpdatePathAttributeMPUnreachNLRI ((pProc + PAHlen), lenAttr, bgpInfo);
219+ break;
220+ default:
221+ ret = 1;
222+ break;
223+ }
224+ if (ret==0) {return 0;}
225+ else if (ret< 0) {return -1;}
226+
227+
228+ /* end proc */
229+ pProc += (PAHlen+lenAttr);
230+ modlenPathAttr -= (PAHlen+lenAttr);
231+ } while (modlenPathAttr>0);
232+ if (modlenPathAttr<0) {return -1;}
233+
234+ return 1;
235+}
236+
237+/*******************************************************************************
238+ * Path attribute type 14: *****************************************************
239+ *
240+ ******************************************************************************/
241+static int BGPUpdatePathAttributeMPreachNLRI (u_int8_t *msg, ssize_t size, BGPUpdateInfo *bgpInfo)
242+{
243+ int ret;
244+ ssize_t len;
245+ BGPUpdateMRNLRI *pt;
246+ pt = (BGPUpdateMRNLRI *)msg;
247+ bgpInfo->PANLRIAFI = be16toh (pt->afi);
248+ bgpInfo->PANLRIAFIsub = pt->safi;
249+ len = (ssize_t)pt->len;
250+ ret = BGPMessagesAddress ((u_int8_t *)(pt+1)+len+1, size - (sizeof (BGPUpdateMRNLRI) + len + 1), &bgpInfo->PANLRIList, &bgpInfo->PANLRINum);
251+ if (ret==0 || ret <0) {
252+ bgpInfo->PANLRIAFI = 0;
253+ bgpInfo->PANLRIAFIsub = 0;
254+ return ret;
255+ }
256+
257+ return 1;
258+}
259+
260+/*******************************************************************************
261+ * Path attribute type 15: *****************************************************
262+ *
263+ ******************************************************************************/
264+static int BGPUpdatePathAttributeMPUnreachNLRI (u_int8_t *msg, ssize_t size, BGPUpdateInfo *bgpInfo)
265+{
266+ int ret;
267+ BGPUpdateMRUnNLRI *pt;
268+ pt = (BGPUpdateMRUnNLRI *)msg;
269+ bgpInfo->PAwithdrawnAFI = be16toh (pt->afi);
270+ bgpInfo->PAwithdrawnAFIsub = pt->safi;
271+ ret = BGPMessagesAddress ((u_int8_t *)(pt+1), size - sizeof (BGPUpdateMRUnNLRI), &bgpInfo->PAwithdrawnList, &bgpInfo->PAwithdrawnNum);
272+ if (ret==0 || ret <0) {
273+ bgpInfo->PAwithdrawnAFI = 0;
274+ bgpInfo->PAwithdrawnAFIsub = 0;
275+ return ret;
276+ }
277+
278+ return 1;
279+}
280+
281+/*******************************************************************************
282+ * BGP messages ****************************************************************
283+ *
284+ ******************************************************************************/
285+void freeBGPupdateInfo (BGPUpdateInfo *bgpInfo)
286+{
287+ if (bgpInfo->withdrawnList !=NULL) {free (bgpInfo->withdrawnList );}
288+ if (bgpInfo->PANLRIList !=NULL) {free (bgpInfo->PANLRIList );}
289+ if (bgpInfo->PAwithdrawnList!=NULL) {free (bgpInfo->PAwithdrawnList);}
290+ if (bgpInfo->NLRIList !=NULL) {free (bgpInfo->NLRIList );}
291+}
292+
293+/*******************************************************************************
294+ * get BGP target Address ******************************************************
295+ *
296+ ******************************************************************************/
297+int BGPMessagesAddress (u_int8_t *area, ssize_t siz, struct NLRIInfo **List, int *num)
298+{
299+ struct NLRIInfo *pbuf, *pTmp;
300+ u_int8_t *pProc;
301+ ssize_t modSiz, prefixSiz;
302+
303+ pbuf = *List;
304+ if (area==NULL) {return 0;}
305+ else if (siz<2 ) {return 0;}
306+ pProc = area;
307+ modSiz = siz;
308+
309+ do {
310+ prefixSiz = ((int)*pProc)>>3;
311+ if ((((int)*pProc) & 0x7)!=0) {prefixSiz++;}
312+ if (modSiz<(prefixSiz+1)) {goto sizeError;}
313+ pTmp = (struct NLRIInfo *)realloc (pbuf, ((*num)+1) * sizeof (struct NLRIInfo));
314+ if (pTmp==NULL) {goto mallocError;}
315+ pbuf = pTmp;
316+
317+ (void) memset ((pbuf+(*num)), 0, sizeof (struct NLRIInfo));
318+ (void) memcpy (&(pbuf+(*num))->prefix, (pProc+1), prefixSiz);
319+ (pbuf+(*num))->prefixLen = (int)*pProc;
320+ (*num)++;
321+
322+#if DEBUG == 1 && 0
323+ printf ("prefixLen: %d, prefixSize: %d\n", (pbuf+(*num)-1)->prefixLen, prefixSiz);
324+ HEXoutput ((u_int8_t *)pbuf, (*num) * sizeof (struct NLRIInfo), 256);
325+#endif
326+
327+ pProc += (prefixSiz + 1);
328+ modSiz -= (prefixSiz + 1);
329+ } while (modSiz>0);
330+ if (modSiz<0) {goto sizeError;}
331+ *List = pbuf;
332+ return 1;
333+
334+ mallocError:
335+ sizeError:
336+ if (pbuf!=NULL) {free (pbuf);}
337+ return 0;
338+}
--- trunk/libbgp/Makefile.am (revision 3)
+++ trunk/libbgp/Makefile.am (revision 4)
@@ -1,6 +1,6 @@
11 noinst_LIBRARIES = libbgp.a
22 include_HEADERS = bgp.h
3-libbgp_a_SOURCES = bgp.h
3+libbgp_a_SOURCES = bgp.h getBGPmessages.c
44 libbgp_a_SOURCES +=
55 libbgp_a_SOURCES +=
66 libbgp_a_SOURCES +=
--- trunk/libbgp/bgp.h (revision 3)
+++ trunk/libbgp/bgp.h (revision 4)
@@ -33,7 +33,11 @@
3333 #if !defined(_SYS_TIME_H) && !defined(_SYS_TIME_H_)
3434 # include <sys/time.h>
3535 #endif
36+#if !defined(_NETINET_IN_H) && !defined(_NETINET_IN_H_)
37+# include <netinet/in.h>
38+#endif
3639
40+
3741 /*******************************************************************************
3842 * Define *********************************************************************/
3943 #define LIBBGP_MAXLENGTH 4096
@@ -78,6 +82,62 @@
7882 /*******************************************************************************
7983 * structure & typedef ********************************************************/
8084 /*+==========================================================================+**
85+ *| BGP Info |**
86+ *+==========================================================================+*/
87+/*******************************************************************************
88+ * Union: address area ********************************************************/
89+#ifndef UNION_ADDRAREA
90+# define UNION_ADDRAREA
91+union addrarea {
92+ struct in_addr inet4;
93+ struct in6_addr inet6;
94+};
95+#endif
96+/*******************************************************************************
97+ * struct: NLRI Info **********************************************************/
98+#ifndef STRUCT_NLRIINFO
99+# define STRUCT_NLRIINFO
100+struct NLRIInfo {
101+ int prefixLen;
102+ union addrarea prefix;
103+};
104+#endif
105+
106+/*+==========================================================================+**
107+ *| BGP Info |**
108+ *+==========================================================================+*/
109+#ifndef STRUCT_BGP_UPDATE_INFO
110+# define STRUCT_BGP_UPDATE_INFO
111+typedef struct {
112+ /*****************************************************************************
113+ * withdrawn Routes *********************************************************/
114+ u_int16_t withdrawnAFI; /* [IANA-AF] "Address Family Numbers" */
115+ int withdrawnNum;
116+ struct NLRIInfo *withdrawnList;
117+
118+ /*****************************************************************************
119+ * pathAttribute ************************************************************/
120+ /* type: 14, MP_REACH_NLRI */
121+ u_int16_t PANLRIAFI; /* [IANA-AF] "Address Family Numbers" */
122+ u_int8_t PANLRIAFIsub;
123+ union addrarea PANLRINextHop;
124+ int PANLRINum;
125+ struct NLRIInfo *PANLRIList;
126+ /* type: 15, MP_UNREACH_NLRI */
127+ u_int16_t PAwithdrawnAFI; /* [IANA-AF] "Address Family Numbers" */
128+ u_int8_t PAwithdrawnAFIsub;
129+ int PAwithdrawnNum;
130+ struct NLRIInfo *PAwithdrawnList;
131+
132+ /*****************************************************************************
133+ * NLRI *********************************************************************/
134+ u_int16_t NLRIAFI; /* [IANA-AF] "Address Family Numbers" */
135+ int NLRINum;
136+ struct NLRIInfo *NLRIList;
137+} BGPUpdateInfo;
138+#endif
139+
140+/*+==========================================================================+**
81141 *| BGP Messages Header |**
82142 *+==========================================================================+*/
83143 /* BGP header common
@@ -134,6 +194,7 @@
134194 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
135195 ******************************************************************************/
136196 typedef u_int16_t BGPUpdateLength; /* for withdrawn routes or total path attribute length */
197+
137198 /* BGP update path attributes
138199 * 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
139200 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
@@ -140,6 +201,9 @@
140201 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
141202 * | Attr. flags | Attr Type | length(1 or 2 Byte) |
142203 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
204+ * http://tools.ietf.org/html/rfc4271
205+ * http://tools.ietf.org/html/rfc4760
206+ * http://www.iana.org/assignments/bgp-parameters/bgp-parameters.xhtml
143207 ******************************************************************************/
144208 typedef struct {
145209 u_int8_t attrFlag;
@@ -163,4 +227,34 @@
163227 #define BGP_UPDATE_PATHATTR_TYPE_CLUSTER_LIST 10
164228 #endif
165229
230+/* Multiprotocol Reachable NLRI - MP_REACH_NLRI (Type Code 14):
231+ * 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
232+ * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
233+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
234+ * | Address Family Identifier | SubsequentAFI | Length |
235+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
236+ * | Network Address of Next Hop (variable) |
237+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
238+ * | Reserved | NLRI (variable) |
239+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
240+ * http://www.iana.org/assignments/bgp-parameters/bgp-parameters.xhtml
241+ * http://tools.ietf.org/html/rfc4760
242+ ******************************************************************************/
243+typedef struct {
244+ u_int16_t afi;
245+ u_int8_t safi;
246+ u_int8_t len;
247+} __attribute__((__packed__)) BGPUpdateMRNLRI;
248+typedef struct {
249+ u_int16_t afi;
250+ u_int8_t safi;
251+} __attribute__((__packed__)) BGPUpdateMRUnNLRI;
252+
253+
254+/*******************************************************************************
255+ * function *******************************************************************/
256+/*=getBGPmessages.c===========================================================*/
257+int BGPupdateMessages (u_int8_t *, ssize_t, BGPUpdateInfo *);
258+void freeBGPupdateInfo (BGPUpdateInfo *);
259+
166260 #endif
--- trunk/bmpStation/bmpStationLib.c (revision 3)
+++ trunk/bmpStation/bmpStationLib.c (revision 4)
@@ -52,6 +52,9 @@
5252 #if !defined(_SYS_STAT_H_) && !defined(_SYS_STAT_H)
5353 # include <sys/stat.h>
5454 #endif
55+#if !defined(_UNISTD_H) && !defined(_UNISTD_H_)
56+# include <unistd.h>
57+#endif
5558
5659
5760 /*%''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''%**
@@ -98,11 +101,6 @@
98101
99102 return;
100103
101- free_data2:
102- umask (mode);
103- free (strLog);
104- return ;
105-
106104 fin_va:
107105 va_end(ap);
108106 free_data:
--- trunk/bmpStation/bmpRead.c (revision 3)
+++ trunk/bmpStation/bmpRead.c (revision 4)
@@ -113,7 +113,6 @@
113113
114114 /*******************************************************************************
115115 * functions ******************************************************************/
116-static int getBMPLogInfo (BMPLogInfoSet *, u_int8_t *, ssize_t);
117116
118117
119118 /* old */
@@ -307,15 +306,7 @@
307306 /*%''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''%**
308307 *: get BMP data each version :**
309308 *%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,%*/
310-/*******************************************************************************
311- * get BMP log infomation *****************************************************/
312-static int getBMPLogInfo (BMPLogInfoSet *BMPLogInfo, u_int8_t *rdata, ssize_t dlen)
313-{
314- return 1;
315-}
316309
317-
318-
319310 /*******************************************************************************
320311 * BMP v1 data ****************************************************************/
321312 static int BMPv1Data (BMPLogInfoSet *BMPLogInfo, u_int8_t *rdata, ssize_t dlen)
@@ -653,7 +644,6 @@
653644 {
654645 int rsize;
655646 BMPMsgPeerDown *BMPPeerDownHeader;
656- u_int8_t *msgData;
657647 BGPCommonHeader *BGPHeader;
658648 char peerAddr[MAXPATHLEN];
659649 rsize = sizeof (BMPMsgPeerDown);
--- trunk/bmpAnalysis/bmpAnalysis.c (revision 3)
+++ trunk/bmpAnalysis/bmpAnalysis.c (revision 4)
@@ -70,16 +70,18 @@
7070 #if !defined(_NETINET_IN_H) && !defined(_NETINET_IN_H_)
7171 # include <netinet/in.h>
7272 #endif
73+#if !defined(_ARPA_INET_H) && !defined(_ARPA_INET_H_)
74+# include <arpa/inet.h>
75+#endif
76+#if !defined(_SYS_TYPES_H) && !defined(_SYS_TYPES_H_)
77+# include <sys/types.h>
78+#endif
7379
7480
7581
7682 #if 0
77-#include <sys/types.h>
78-#include <arpa/inet.h>
7983
80-#if !defined(_SYS_TYPES_H) && !defined(_SYS_TYPES_H_)
81-# include <sys/types.h>
82-#endif
84+
8385 #if !defined(_SYS_SELECT_H) && !defined(_SYS_SELECT_H_)
8486 # include <sys/select.h>
8587 #endif
@@ -166,7 +168,7 @@
166168 pmsgBondLast += rlen;
167169 pmsgBondRead = pmsgBondStore;
168170 datVal = pmsgBondLast-pmsgBondRead;
169- if (FLGISSET(lastParam.enaFlag, OPTENAFLGDEBUG) && FLGISSET(lastParam.flags, OPTFLGDEBUG)) {
171+ if (FLGISSET(lastParam.enaFlag, OPTENAFLGDEBUG) && FLGISSET(lastParam.flags, OPTFLGDEBUG) && 0) {
170172 HEXoutput (pmsgBondStore, datVal, 256);
171173 }
172174
@@ -244,44 +246,51 @@
244246 t = tv.tv_sec;
245247 date = localtime (&t);
246248 (void) memset (strBuf, 0, sizeof (strBuf));
247- strftime (strBuf, sizeof (strBuf), "%Y/%m/%d %H/%M/%S", date);
248- snprintf (str, siz, "%s.%03d", strBuf, tv.tv_usec/1000);
249+ strftime (strBuf, sizeof (strBuf), "%Y/%m/%d %H:%M:%S", date);
250+ snprintf (str, siz, "%s.%03ld", strBuf, tv.tv_usec/1000);
249251
250252 return 1;
251253 }
252254
255+#if 0
253256 static int msgAddr (u_int8_t *data, char *str, ssize_t siz, int aft)
254257 {
258+ union addrarea addr;
255259 int len, nb;
256- struct in6_addr sin6_addr;
257260 char addrTmp[64];
258261 len = (int)*data;
259262 nb = (len >>3);
260263 if ((len&0x7)!=0) {nb++;}
261- (void)memset ((char *)&sin6_addr, 0, sizeof (sin6_addr));
264+ (void)memset ((char *)&addr, 0, sizeof (addr));
262265 (void)memset (addrTmp, 0, sizeof (addrTmp));
263- memcpy (&sin6_addr, (data+1), nb);
266+ memcpy (&addr, (data+1), nb);
264267
265- inet_ntop (aft, &sin6_addr, addrTmp, sizeof (addrTmp));
268+ inet_ntop (aft, &addr, addrTmp, sizeof (addrTmp));
266269 snprintf (str, siz, "%s/%d", addrTmp, len);
267270
268271 return nb+1;
269272 }
273+#endif
270274
271275 /*******************************************************************************
272276 * BMP Update Messages ********************************************************/
273277 static int bgpUpdateMessage (BMPLogInfoSet *pbmp, BGPCommonHeader *pbgp)
274278 {
275- BGPUpdateLength *plenWdrawn, *plenPattr, lenWdrawn, lenPattr;
279+ int i;
280+ BGPUpdateInfo bgpInfo;
276281 struct timeval rtrTime, rcvTime;
277282 char rtrStrTime[30], rcvStrTime[30];
278- int rtn;
279- u_int8_t *pproc;
280-
281283 struct in_addr *sin_addr;
282284 struct in6_addr *sin6_addr;
283285 char peerAddr[64];
284286 char updateAddr[64];
287+#if 0
288+ BGPUpdatePathAttr *pPAttr;
289+ BGPUpdateLength *plenWdrawn, *plenPattr, lenWdrawn, lenPattr;
290+ int palen;
291+ int rtn, BGPLen;
292+ u_int8_t *pproc;
293+#endif
285294
286295 (void)memset (rtrStrTime, 0, sizeof (rtrStrTime));
287296 (void)memset (rcvStrTime, 0, sizeof (rcvStrTime));
@@ -301,22 +310,111 @@
301310 inet_ntop (AF_INET, sin_addr, peerAddr, sizeof (peerAddr));
302311 }
303312
304-
305- plenWdrawn = (BGPUpdateLength *)(pbgp+1);
306- lenWdrawn = be16toh (*plenWdrawn);
307- plenPattr = (void *)(plenWdrawn+1) + lenWdrawn;
308- lenPattr = be16toh (*plenPattr);
309- if (FLGISSET(lastParam.enaFlag, OPTENAFLGDEBUG) && FLGISSET(lastParam.flags, OPTFLGDEBUG)) {
310- printf ("Withdrawn length: %hu\n", lenWdrawn);
311- HEXoutput ((u_int8_t *)plenWdrawn, lenWdrawn+2, 256);
312- printf ("path attribute length: %hu\n", lenPattr);
313- HEXoutput ((u_int8_t *)plenPattr, lenPattr+2, 256);
313+ (void) memset (&bgpInfo, 0, sizeof (BGPUpdateInfo));
314+ BGPupdateMessages ((u_int8_t *)pbgp, be16toh (pbgp->length), &bgpInfo);
315+
316+ /* withdrawn */
317+ for (i=0; i<bgpInfo.withdrawnNum; i++) {
318+ (void) memset (updateAddr, 0, sizeof (updateAddr));
319+ if (bgpInfo.withdrawnAFI==1) {
320+ inet_ntop (AF_INET , &(bgpInfo.withdrawnList+i)->prefix, updateAddr, sizeof (updateAddr));
321+ } else if (bgpInfo.withdrawnAFI==2) {
322+ inet_ntop (AF_INET6, &(bgpInfo.withdrawnList+i)->prefix, updateAddr, sizeof (updateAddr));
323+ }
324+ if (bgpInfo.withdrawnAFI==1 || bgpInfo.withdrawnAFI==2) {
325+ printf ("%s : %s peer: %s(%u), withdrawn %s/%d\n", rcvStrTime, rtrStrTime, peerAddr, be32toh (pbmp->peerAS), updateAddr, (bgpInfo.withdrawnList+i)->prefixLen);
326+ }
314327 }
328+ /* mp NLRI */
329+ for (i=0; i<bgpInfo.PANLRINum; i++) {
330+ (void) memset (updateAddr, 0, sizeof (updateAddr));
331+ if (bgpInfo.PANLRIAFI==1) {
332+ inet_ntop (AF_INET , &(bgpInfo.PANLRIList+i)->prefix, updateAddr, sizeof (updateAddr));
333+ } else if (bgpInfo.PANLRIAFI==2) {
334+ inet_ntop (AF_INET6, &(bgpInfo.PANLRIList+i)->prefix, updateAddr, sizeof (updateAddr));
335+ }
336+ if (bgpInfo.PANLRIAFI==1 || bgpInfo.PANLRIAFI==2) {
337+ printf ("%s : %s peer: %s(%u), update %s/%d\n", rcvStrTime, rtrStrTime, peerAddr, be32toh (pbmp->peerAS), updateAddr, (bgpInfo.PANLRIList+i)->prefixLen);
338+ }
339+ }
340+ /* MP withdrawn */
341+ for (i=0; i<bgpInfo.PAwithdrawnNum; i++) {
342+ (void) memset (updateAddr, 0, sizeof (updateAddr));
343+ if (bgpInfo.PAwithdrawnAFI==1) {
344+ inet_ntop (AF_INET , &(bgpInfo.PAwithdrawnList+i)->prefix, updateAddr, sizeof (updateAddr));
345+ } else if (bgpInfo.PAwithdrawnAFI==2) {
346+ inet_ntop (AF_INET6, &(bgpInfo.PAwithdrawnList+i)->prefix, updateAddr, sizeof (updateAddr));
347+ }
348+ if (bgpInfo.PAwithdrawnAFI==1 || bgpInfo.PAwithdrawnAFI==2) {
349+ printf ("%s : %s peer: %s(%u), withdrawn %s/%d\n", rcvStrTime, rtrStrTime, peerAddr, be32toh (pbmp->peerAS), updateAddr, (bgpInfo.PAwithdrawnList+i)->prefixLen);
350+ }
351+ }
352+ /* NLRI */
353+ for (i=0; i<bgpInfo.NLRINum; i++) {
354+ (void) memset (updateAddr, 0, sizeof (updateAddr));
355+ if (bgpInfo.NLRIAFI==1) {
356+ inet_ntop (AF_INET , &(bgpInfo.NLRIList+i)->prefix, updateAddr, sizeof (updateAddr));
357+ } else if (bgpInfo.NLRIAFI==2) {
358+ inet_ntop (AF_INET6, &(bgpInfo.NLRIList+i)->prefix, updateAddr, sizeof (updateAddr));
359+ }
360+ if (bgpInfo.NLRIAFI==1 || bgpInfo.NLRIAFI==2) {
361+ printf ("%s : %s peer: %s(%u), update %s/%d\n", rcvStrTime, rtrStrTime, peerAddr, be32toh (pbmp->peerAS), updateAddr, (bgpInfo.NLRIList+i)->prefixLen);
362+ }
363+ }
315364
365+
366+
367+ freeBGPupdateInfo (&bgpInfo);
368+#if 0
316369 #if 1
317- if (lenWdrawn>0) {
318- pproc = (u_int8_t *)(plenWdrawn+1);
370+ if (lenPattr>0) {
371+ u_int8_t *pt;
372+ int len;
373+ pproc = (u_int8_t *)(plenPattr+1);
374+ pPAttr = (BGPUpdatePathAttr *)pproc;
319375 do {
376+ int PAHlen;
377+ PAHlen = sizeof (BGPUpdatePathAttr);
378+ if ((pPAttr->attrFlag & 0x80)==0x80) {
379+ /* optional path attribute proc */
380+ }
381+ if ((pPAttr->attrFlag & 0x40)==0x40) {
382+ /* transitive path attribute proc */
383+ }
384+ if ((pPAttr->attrFlag & 0x20)==0x20) {
385+ /* partial path attribute proc */
386+ }
387+ if ((pPAttr->attrFlag & 0x10)==0x10) {
388+ PAHlen += 2;
389+ palen = be16toh (*(u_int16_t *)(pPAttr+1));
390+ } else {
391+ PAHlen++;
392+ palen = (int)*(u_int8_t *)(pPAttr+1);
393+ }
394+ printf ("palen: %d, PAHlen: %d\n", palen, PAHlen);
395+ HEXoutput ((u_int8_t *)pproc, (palen + PAHlen), 256);
396+
397+ switch (pPAttr->attrType) {
398+ case 14: /* Multiprotocol Reachable NLRI */
399+ pt = (u_int8_t *)(pPAttr+1);
400+ len = 5 + *(pt+3);
401+ break;
402+ }
403+
404+ lenPattr -= palen + PAHlen;
405+ pproc += palen + PAHlen;
406+ pPAttr = (BGPUpdatePathAttr *)pproc;
407+ printf ("lenPAttr: %d\n", lenPattr);
408+ } while (lenPattr>0);
409+ if (lenPattr<0) {return -1;}
410+ }
411+ if (BGPLen>0) {
412+ if (FLGISSET(lastParam.enaFlag, OPTENAFLGDEBUG) && FLGISSET(lastParam.flags, OPTFLGDEBUG)) {
413+ printf ("BGP Len: %d\n", BGPLen);
414+ HEXoutput ((u_int8_t *)pproc, BGPLen, 256);
415+ }
416+
417+ do {
320418 (void) memset (updateAddr, 0, sizeof (updateAddr));
321419
322420 if (FLGISSET(pbmp->peerFlags, BMP_PEERFLG_VFLG_IPv6)) {
@@ -324,19 +422,15 @@
324422 } else {
325423 rtn = msgAddr (pproc, updateAddr, sizeof (updateAddr), AF_INET);
326424 }
327- lenWdrawn -= rtn;
425+ BGPLen -= rtn;
328426 pproc += rtn;
329- printf ("%s : %s peer: %s(%u), withdrawn %s mod %d\n", rcvStrTime, rtrStrTime, peerAddr, be32toh (pbmp->peerAS), updateAddr, lenWdrawn);
330- } while (lenWdrawn>0);
331- if (lenWdrawn<0) {return -1;}
332- }
333- else if (plenPattr>0) {
334- printf ("%s : %s peer: %s(%u), update \n", rcvStrTime, rtrStrTime, peerAddr, be32toh (pbmp->peerAS));
427+ printf ("%s : %s peer: %s(%u), update %s mod %d\n", rcvStrTime, rtrStrTime, peerAddr, be32toh (pbmp->peerAS), updateAddr, BGPLen);
428+ } while (BGPLen>0);
429+ if (BGPLen<0) {return -1;}
335430 }
336- else {
337- printf ("%s : %s peer: %s(%u), can't understand\n", rcvStrTime, rtrStrTime, peerAddr, be32toh (pbmp->peerAS));
338- }
431+
339432 #endif
433+#endif
340434
341435 return 1;
342436 }
@@ -350,7 +444,7 @@
350444 BGPCommonHeader *pbgpHeader; /* pbgpHeader is BGP update message Point */
351445 pbmpLogHeader = (BMPLogInfoSet *)bData;
352446 pbgpHeader = (BGPCommonHeader *)(pbmpLogHeader+1);
353- if (FLGISSET(lastParam.enaFlag, OPTENAFLGDEBUG) && FLGISSET(lastParam.flags, OPTFLGDEBUG)) {
447+ if (FLGISSET(lastParam.enaFlag, OPTENAFLGDEBUG) && FLGISSET(lastParam.flags, OPTFLGDEBUG) && 0) {
354448 HEXoutput ((u_int8_t *)pbmpLogHeader, be32toh (pbmpLogHeader->msgLen), 256);
355449 }
356450
--- trunk/include/selfLib.h (revision 3)
+++ trunk/include/selfLib.h (revision 4)
@@ -56,11 +56,6 @@
5656
5757 /*******************************************************************************
5858 * Structure & union **********************************************************/
59-/*=address area===============================================================*/
60-union addrarea {
61- struct in_addr in4;
62- struct in6_addr in6;
63-};
6459
6560 /*******************************************************************************
6661 * Functions ******************************************************************/