• R/O
  • SSH
  • HTTPS

Commit

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

Révision6 (tree)
l'heure2018-09-30 18:14:42
Auteuryuki0220

Message de Log

add bmpStation-0.1

Change Summary

Modification

--- release/bmpStation-0.1/libbgp/bgp.h (nonexistent)
+++ release/bmpStation-0.1/libbgp/bgp.h (revision 6)
@@ -0,0 +1,297 @@
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+#if !defined(BGP_H__)
26+#define BGP_H__ 1
27+
28+/*******************************************************************************
29+ * include ********************************************************************/
30+#if !defined(_SYS_TYPES_H) && !defined(_SYS_TYPES_H_)
31+# include <sys/types.h>
32+#endif
33+#if !defined(_SYS_TIME_H) && !defined(_SYS_TIME_H_)
34+# include <sys/time.h>
35+#endif
36+#if !defined(_NETINET_IN_H) && !defined(_NETINET_IN_H_)
37+# include <netinet/in.h>
38+#endif
39+
40+
41+/*******************************************************************************
42+ * Define *********************************************************************/
43+#define LIBBGP_MAXLENGTH 4096
44+#define LIBBGP_MAXMSGLEN 4096
45+/*+==========================================================================+**
46+ *| BGP Messeages Info |**
47+ *+==========================================================================+*/
48+/*=Messages type==============================================================*/
49+#define BGP_MSGTYPE_OPEN 1
50+#define BGP_MSGTYPE_UPDATE 2
51+#define BGP_MSGTYPE_NOTIFICATION 3
52+#define BGP_MSGTYPE_KEEPALIVE 4
53+/* OLD */
54+#define BGPMSGTYPE_OPEN 1
55+#define BGPMSGTYPE_UPDATE 2
56+#define BGPMSGTYPE_NOTIFICATION 3
57+#define BGPMSGTYPE_KEEPALIVE 4
58+/*=BGP Update path attribute flag=============================================*/
59+#define BGP_UPDATE_PATHATTR_FLG_OPTIONAL 0x80
60+#define BGP_UPDATE_PATHATTR_FLG_TRANSITIVE 0x40
61+#define BGP_UPDATE_PATHATTR_FLG_PARTIAL 0x20
62+/* extend flag is 0, next(3rd) octet is length.
63+ * extend flag is 1, 3rd and 4th octet is length
64+ */
65+#define BGP_UPDATE_PATHATTR_FLG_EXTEND_LENGTH 0x10
66+/*=BGP Update path attribute==================================================*/
67+#define BGP_UPDATE_PATHATTR_TYPE_ORIGIN 1
68+#define BGP_UPDATE_PATHATTR_TYPE_AS_PATH 2
69+#define BGP_UPDATE_PATHATTR_TYPE_NEXT_HOP 3
70+#define BGP_UPDATE_PATHATTR_TYPE_MED 4
71+#define BGP_UPDATE_PATHATTR_TYPE_LOCAL_PREF 5
72+#define BGP_UPDATE_PATHATTR_TYPE_ATOMIC_AGG 6
73+#define BGP_UPDATE_PATHATTR_TYPE_AGGREGATOR 7
74+#define BGP_UPDATE_PATHATTR_TYPE_COMMUNITY 8
75+#define BGP_UPDATE_PATHATTR_TYPE_ORIGINATOR 9
76+#define BGP_UPDATE_PATHATTR_TYPE_CLUSTER_LIST 10
77+
78+
79+/*******************************************************************************
80+ * Macro **********************************************************************/
81+
82+/*******************************************************************************
83+ * structure & typedef ********************************************************/
84+/*+==========================================================================+**
85+ *| BGP Info |**
86+ *+==========================================================================+*/
87+/*******************************************************************************
88+ * Union: AS Number area ********************************************************/
89+#ifndef UNION_AS_PathArea
90+# define UNION_AS_PathArea
91+union AS_PathArea {
92+ u_int16_t AS2;
93+ u_int32_t AS4;
94+};
95+#endif
96+/*******************************************************************************
97+ * Union: address area ********************************************************/
98+#ifndef UNION_ADDRAREA
99+# define UNION_ADDRAREA
100+union addrarea {
101+ struct in_addr inet4;
102+ struct in6_addr inet6;
103+};
104+#endif
105+/*******************************************************************************
106+ * struct: NLRI Info **********************************************************/
107+#ifndef STRUCT_NLRIINFO
108+# define STRUCT_NLRIINFO
109+struct NLRIInfo {
110+ int prefixLen;
111+ union addrarea prefix;
112+};
113+#endif
114+
115+/*+==========================================================================+**
116+ *| BGP Info |**
117+ *+==========================================================================+*/
118+#ifndef STRUCT_BGP_UPDATE_INFO
119+# define STRUCT_BGP_UPDATE_INFO
120+typedef struct {
121+ /*****************************************************************************
122+ * withdrawn Routes *********************************************************/
123+ u_int16_t withdrawnAFI; /* [IANA-AF] "Address Family Numbers" */
124+ int withdrawnNum;
125+ struct NLRIInfo *withdrawnList;
126+
127+ /*****************************************************************************
128+ * pathAttribute ************************************************************/
129+ /* type: 1, Origin */
130+ u_int8_t PAOrigin;
131+ /* type: 2, AS PAth */
132+ int PAPathNum;
133+ union AS_PathArea *PAPathList;
134+ /* type: 4, MED */
135+ int PAMedBool;
136+ u_int32_t PAMed;
137+ /* type: 5, Local pref */
138+ int PALPBool;
139+ u_int32_t PALP;
140+
141+
142+ /* type: 14, MP_REACH_NLRI */
143+ u_int16_t PANLRIAFI; /* [IANA-AF] "Address Family Numbers" */
144+ u_int8_t PANLRIAFIsub;
145+ union addrarea PANLRINextHop;
146+ int PANLRINum;
147+ struct NLRIInfo *PANLRIList;
148+ /* type: 15, MP_UNREACH_NLRI */
149+ u_int16_t PAwithdrawnAFI; /* [IANA-AF] "Address Family Numbers" */
150+ u_int8_t PAwithdrawnAFIsub;
151+ int PAwithdrawnNum;
152+ struct NLRIInfo *PAwithdrawnList;
153+
154+ /*****************************************************************************
155+ * NLRI *********************************************************************/
156+ u_int16_t NLRIAFI; /* [IANA-AF] "Address Family Numbers" */
157+ int NLRINum;
158+ struct NLRIInfo *NLRIList;
159+} BGPUpdateInfo;
160+#endif
161+
162+/*+==========================================================================+**
163+ *| BGP Messages Header |**
164+ *+==========================================================================+*/
165+/* BGP header common
166+ * 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
167+ * 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
168+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
169+ * | Marker (16 byte) |
170+ * | |
171+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
172+ * | Length | msg Type |
173+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
174+ ******************************************************************************/
175+typedef struct {
176+ u_int32_t Maker[4];
177+ u_int16_t length;
178+ u_int8_t type;
179+} __attribute__((__packed__)) BGPCommonHeader;
180+
181+/* Open Messages
182+ * 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
183+ * 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
184+ * +-+-+-+-+-+-+-+-+
185+ * | Version |
186+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
187+ * | MY AS(sender) |
188+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
189+ * | Hold Time |
190+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
191+ * | BGP Identifier |
192+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
193+ * | OPt Parm Len |
194+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
195+ * | OPtional parameter (variable) |
196+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
197+ ******************************************************************************/
198+typedef struct {
199+ u_int8_t version;
200+ u_int16_t asn;
201+ u_int16_t holdtime;
202+ u_int32_t BGPid;
203+ u_int8_t optLen;
204+} __attribute__((__packed__)) BGPOpenMessage;
205+
206+
207+/* BGP Update Messages
208+ * 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
209+ * 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
210+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
211+ * | Withdrawn Routes Length | Withdrawn Routes (variable) |
212+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
213+ * | Total path attribute length | path attribute (variable) |
214+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
215+ * | NLRI (variable) |
216+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
217+ ******************************************************************************/
218+typedef u_int16_t BGPUpdateLength; /* for withdrawn routes or total path attribute length */
219+
220+/* BGP update path attributes
221+ * 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
222+ * 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
223+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
224+ * | Attr. flags | Attr Type | length(1 or 2 Byte) |
225+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
226+ * http://tools.ietf.org/html/rfc4271
227+ * http://tools.ietf.org/html/rfc4760
228+ * http://www.iana.org/assignments/bgp-parameters/bgp-parameters.xhtml
229+ ******************************************************************************/
230+typedef struct {
231+ u_int8_t attrFlag;
232+ u_int8_t attrType;
233+} __attribute__((__packed__)) BGPUpdatePathAttr;
234+
235+#if 0
236+typedef u_int8_t BGPUpdatePathAttr_Origin_Unit;
237+typedef u_int8_t BGPUpdatePathAttr_AsPath_Type;
238+ typedef u_int16_t BGPUpdatePathAttr_AsPath_Unit;
239+
240+#define BGP_UPDATE_PATHATTR_TYPE_ORIGIN 1
241+#define BGP_UPDATE_PATHATTR_TYPE_AS_PATH 2
242+#define BGP_UPDATE_PATHATTR_TYPE_NEXT_HOP 3
243+#define BGP_UPDATE_PATHATTR_TYPE_MED 4
244+#define BGP_UPDATE_PATHATTR_TYPE_LOCAL_PREF 5
245+#define BGP_UPDATE_PATHATTR_TYPE_ATOMIC_AGG 6
246+#define BGP_UPDATE_PATHATTR_TYPE_AGGREGATOR 7
247+#define BGP_UPDATE_PATHATTR_TYPE_COMMUNITY 8
248+#define BGP_UPDATE_PATHATTR_TYPE_ORIGINATOR 9
249+#define BGP_UPDATE_PATHATTR_TYPE_CLUSTER_LIST 10
250+#endif
251+
252+
253+/* AS_PATH (Type Code 2):
254+ * 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
255+ * 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
256+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
257+ * | Address Family Identifier | SubsequentAFI | Length |
258+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
259+ * | Network Address of Next Hop (variable) |
260+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
261+ * | Reserved | NLRI (variable) |
262+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
263+ * http://www.iana.org/assignments/bgp-parameters/bgp-parameters.xhtml
264+ * http://tools.ietf.org/html/rfc4760
265+ ******************************************************************************/
266+
267+/* Multiprotocol Reachable NLRI - MP_REACH_NLRI (Type Code 14):
268+ * 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
269+ * 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
270+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
271+ * | Address Family Identifier | SubsequentAFI | Length |
272+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
273+ * | Network Address of Next Hop (variable) |
274+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
275+ * | Reserved | NLRI (variable) |
276+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
277+ * http://www.iana.org/assignments/bgp-parameters/bgp-parameters.xhtml
278+ * http://tools.ietf.org/html/rfc4760
279+ ******************************************************************************/
280+typedef struct {
281+ u_int16_t afi;
282+ u_int8_t safi;
283+ u_int8_t len;
284+} __attribute__((__packed__)) BGPUpdateMRNLRI;
285+typedef struct {
286+ u_int16_t afi;
287+ u_int8_t safi;
288+} __attribute__((__packed__)) BGPUpdateMRUnNLRI;
289+
290+
291+/*******************************************************************************
292+ * function *******************************************************************/
293+/*=getBGPmessages.c===========================================================*/
294+int BGPupdateMessages (u_int8_t *, ssize_t, BGPUpdateInfo *);
295+void freeBGPupdateInfo (BGPUpdateInfo *);
296+
297+#endif
--- release/bmpStation-0.1/libbgp/getBGPmessages.c (nonexistent)
+++ release/bmpStation-0.1/libbgp/getBGPmessages.c (revision 6)
@@ -0,0 +1,423 @@
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 BGPUpdateAS_Path (u_int8_t *, ssize_t, BGPUpdateInfo *);
43+static int BGPUpdateMED (u_int8_t *, ssize_t, BGPUpdateInfo *);
44+static int BGPUpdateLP (u_int8_t *, ssize_t, BGPUpdateInfo *);
45+static int BGPUpdatePathAttributeMPreachNLRI (u_int8_t *, ssize_t, BGPUpdateInfo *);
46+static int BGPUpdatePathAttributeMPUnreachNLRI (u_int8_t *, ssize_t, BGPUpdateInfo *);
47+/*%''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''%**
48+ *: get BGP Messages process :**
49+ *%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,%*/
50+#define DEBUG 1
51+#if DEBUG == 1
52+static void HEXoutput (u_int8_t *rdata, int len, int max)
53+{
54+ int i;
55+ int outLen;
56+ int counter = -16;
57+ outLen = (len<max?len:max);
58+
59+ printf ("len: %d, output: %d\n", len, outLen);
60+ for (i=0; i<outLen; i++) {
61+ if ((i%16)==0) {counter += 16; printf ("0x%04X:", counter);}
62+ if ((i%2)==0) {printf (" ");}
63+ printf ("%02x", rdata[i]);
64+ if ((i%16)==15) {printf ("\n");}
65+ }
66+ printf ("\n");
67+}
68+#endif
69+
70+/*******************************************************************************
71+ * BGP messages ****************************************************************
72+ *
73+ ******************************************************************************/
74+int BGPupdateMessages (u_int8_t *msg, ssize_t size, BGPUpdateInfo *bgpInfo)
75+{
76+ int i, ret;
77+ ssize_t updateMsgLen, lenNLRI;
78+ BGPCommonHeader *pBGPheader;
79+ BGPUpdateLength *plenWdrawn, *plenPattr, lenWdrawn, lenPattr;
80+ u_int8_t *pProc, *pWdrawn, *pPattr, *pNLRI;
81+ pBGPheader = (BGPCommonHeader *)msg;
82+#if DEBUG == 1 && 0
83+ HEXoutput ((u_int8_t *)msg, size, 256);
84+#endif
85+ if (msg==NULL) {return -1;}
86+ else if (size<sizeof (BGPCommonHeader) ) {return -1;}
87+ else if (size<be16toh (pBGPheader->length)) {return -1;}
88+ else if (pBGPheader->type!=2) {return 0;}
89+ for (i=0; i<4; i++) {if (pBGPheader->Maker[i]!=0xffffffff) {return -1;}}
90+
91+ /*Get Area*******************************************************************/
92+ updateMsgLen = be16toh (pBGPheader->length) - sizeof (BGPCommonHeader);
93+ /* withdrawn area */
94+ pWdrawn = (u_int8_t *)(pBGPheader+1);
95+ lenWdrawn = be16toh (*((BGPUpdateLength *)pWdrawn));
96+ pWdrawn += sizeof (BGPUpdateLength);
97+#if DEBUG == 1 && 0
98+ printf ("withdrawn area: %d\n", lenWdrawn);
99+ HEXoutput ((u_int8_t *)pWdrawn, lenWdrawn, 256);
100+#endif
101+
102+ /* path attribute area */
103+ pPattr = (u_int8_t *)(pWdrawn + lenWdrawn);
104+ lenPattr = be16toh (*((BGPUpdateLength *)pPattr));
105+ pPattr += sizeof (BGPUpdateLength);
106+#if DEBUG == 1 && 0
107+ printf ("path attribute area: %d\n", lenPattr);
108+ HEXoutput ((u_int8_t *)pPattr, lenPattr, 256);
109+#endif
110+
111+ /* NLRI area */
112+ pNLRI = (u_int8_t *)(pPattr + lenPattr);
113+ lenNLRI = updateMsgLen - (sizeof (BGPUpdateLength) * 2 + lenWdrawn + lenPattr);
114+#if DEBUG == 1 && 0
115+ printf ("NLRI area: %d\n", lenNLRI);
116+ HEXoutput ((u_int8_t *)pNLRI, lenNLRI, 256);
117+#endif
118+
119+ /*Check**********************************************************************/
120+ if (lenWdrawn>0) {}
121+ else if (lenPattr >0) {}
122+ else if (lenNLRI >0) {}
123+ else {return -1;}
124+ /*Get BGP Update Infomation**************************************************/
125+ /* withdrawn */
126+ if (lenWdrawn>0) {
127+#if DEBUG == 1 && 0
128+ printf ("wdrawn\n");
129+#endif
130+ bgpInfo->NLRIAFI = 1;
131+ if (!BGPMessagesAddress (pWdrawn, lenWdrawn, &bgpInfo->withdrawnList, &bgpInfo->withdrawnNum)) {return -1;}
132+ }
133+
134+ /* Path attribute */
135+ if (lenPattr>0) {
136+#if DEBUG == 1 && 0
137+ printf ("Path attribute\n");
138+#endif
139+ ret = BGPUpdatePathAttribute (pPattr, lenPattr, bgpInfo);
140+ if (ret==0) {return 0;}
141+ else if (ret< 0) {return -1;}
142+ }
143+
144+ /* NLRI */
145+ if (lenNLRI>0) {
146+#if DEBUG == 1 && 0
147+ printf ("NLRI\n");
148+#endif
149+ bgpInfo->NLRIAFI = 1;
150+ if (!BGPMessagesAddress (pNLRI, lenNLRI, &bgpInfo->NLRIList, &bgpInfo->NLRINum)) {return -1;}
151+ }
152+
153+ return 1;
154+}
155+
156+
157+/*******************************************************************************
158+ * Path attribute process ******************************************************
159+ *
160+ ******************************************************************************/
161+int BGPUpdatePathAttribute (u_int8_t *msg, ssize_t size, BGPUpdateInfo *bgpInfo)
162+{
163+ int ret;
164+ u_int8_t *pProc;
165+ int modlenPathAttr, lenAttr;
166+ ssize_t PathAttrLen, PAHlen;
167+ BGPUpdatePathAttr *pPAttr;
168+
169+ if (msg==NULL) {return -1;}
170+ else if (size<sizeof (BGPUpdatePathAttr)+1) {return -1;}
171+ pProc = msg;
172+ modlenPathAttr = size;
173+ do {
174+#if DEBUG == 1 && 0
175+ printf ("modlenPathAttr: %d\n", modlenPathAttr);
176+#endif
177+ /* header processing */
178+ PAHlen = sizeof (BGPUpdatePathAttr) + 1;
179+ if (modlenPathAttr<PAHlen) {return -1;}
180+ pPAttr = (BGPUpdatePathAttr *)pProc;
181+ if ((pPAttr->attrFlag & 0x80)==0x80) {
182+ /* optional path attribute proc */
183+ }
184+ if ((pPAttr->attrFlag & 0x40)==0x40) {
185+ /* transitive path attribute proc */
186+ }
187+ if ((pPAttr->attrFlag & 0x20)==0x20) {
188+ /* partial path attribute proc */
189+ }
190+ if ((pPAttr->attrFlag & 0x10)==0x10) {
191+ PAHlen++;
192+ if (modlenPathAttr<PAHlen) {return -1;}
193+ lenAttr = be16toh (*(u_int16_t *)(pPAttr+1));
194+ } else {
195+ lenAttr = (int)*(u_int8_t *)(pPAttr+1);
196+ }
197+ if (modlenPathAttr < (PAHlen+lenAttr)) {return -1;}
198+
199+
200+#if DEBUG == 1 && 1
201+ printf ("lenAttr: %d, PAHlen: %d\n", lenAttr, PAHlen);
202+ HEXoutput ((u_int8_t *)pPAttr, (lenAttr + PAHlen), 256);
203+#endif
204+ /* data proc */
205+ switch (pPAttr->attrType) {
206+ case 0: /* reserved */
207+ return -1;
208+ break;
209+ case 1: /* ORIGIN */
210+ bgpInfo->PAOrigin = *(pProc + PAHlen);
211+ ret = 1;
212+ break;
213+#if 0
214+ case 2: /* AS_PATH */
215+ ret = BGPUpdateAS_Path ((pProc + PAHlen), lenAttr, bgpInfo);
216+ break;
217+ case 3: /* NEXT_HOP */
218+ break;
219+#endif
220+ case 4: /* MED */
221+ ret = BGPUpdateMED ((pProc + PAHlen), lenAttr, bgpInfo);
222+ break;
223+ case 5: /* LP */
224+ ret = BGPUpdateLP ((pProc + PAHlen), lenAttr, bgpInfo);
225+ break;
226+ case 14: /* MP_REACH_NLRI */
227+ ret = BGPUpdatePathAttributeMPreachNLRI ((pProc + PAHlen), lenAttr, bgpInfo);
228+ break;
229+ case 15: /* MP_UNREACH_NLRI */
230+ ret = BGPUpdatePathAttributeMPUnreachNLRI ((pProc + PAHlen), lenAttr, bgpInfo);
231+ break;
232+ default:
233+ ret = 1;
234+ break;
235+ }
236+ if (ret==0) {return 0;}
237+ else if (ret< 0) {return -1;}
238+
239+
240+ /* end proc */
241+ pProc += (PAHlen+lenAttr);
242+ modlenPathAttr -= (PAHlen+lenAttr);
243+ } while (modlenPathAttr>0);
244+ if (modlenPathAttr<0) {return -1;}
245+
246+ return 1;
247+}
248+
249+/*******************************************************************************
250+ * Path attribute type 2: *****************************************************
251+ *
252+ ******************************************************************************/
253+static int BGPUpdateAS_Path (u_int8_t *msg, ssize_t size, BGPUpdateInfo *bgpInfo)
254+{
255+ int ret, i;
256+ ssize_t areaSize;
257+ u_int8_t *psegType;
258+ u_int16_t *pAS;
259+ union AS_PathArea *pt;
260+
261+ if (size==0) {return 1;}
262+ psegType = msg;
263+ bgpInfo->PAPathNum = (int)(*(msg+1));
264+ areaSize = bgpInfo->PAPathNum * sizeof (union AS_PathArea);
265+
266+ pt = malloc (areaSize);
267+ if (pt==NULL) {return -1;}
268+ (void) memset (pt, 0, areaSize);
269+ pAS = (u_int16_t *)(msg+2);
270+
271+ for (i=0; i<bgpInfo->PAPathNum; i++) {
272+ (pt+i)->AS2 = be16toh (*(pAS+i));
273+ printf ("AS[%d]: %d\n", i, (pt+i)->AS2);
274+ }
275+
276+ return 1;
277+}
278+
279+/*******************************************************************************
280+ * Path attribute type 4: *****************************************************
281+ *
282+ ******************************************************************************/
283+static int BGPUpdateMED (u_int8_t *msg, ssize_t size, BGPUpdateInfo *bgpInfo)
284+{
285+ int ret, i;
286+ ssize_t areaSize;
287+ u_int8_t *psegType;
288+ u_int16_t *pAS;
289+ union AS_PathArea *pt;
290+
291+ bgpInfo->PAMedBool = 0;
292+ if (size!=4) {return 0;}
293+ bgpInfo->PAMedBool = 1;
294+ bgpInfo->PAMed = be32toh (*(u_int32_t *)msg);
295+ printf ("MED: %d\n", bgpInfo->PAMed);
296+
297+ return 1;
298+}
299+
300+/*******************************************************************************
301+ * Path attribute type 5: *****************************************************
302+ *
303+ ******************************************************************************/
304+static int BGPUpdateLP (u_int8_t *msg, ssize_t size, BGPUpdateInfo *bgpInfo)
305+{
306+ int ret, i;
307+ ssize_t areaSize;
308+ u_int8_t *psegType;
309+ u_int16_t *pAS;
310+ union AS_PathArea *pt;
311+
312+ bgpInfo->PALPBool = 0;
313+ if (size!=4) {return 0;}
314+ bgpInfo->PALPBool = 1;
315+ bgpInfo->PALP = be32toh (*(u_int32_t *)msg);
316+ printf ("LP: %d\n", bgpInfo->PALP);
317+
318+ return 1;
319+}
320+
321+/*******************************************************************************
322+ * Path attribute type 14: *****************************************************
323+ *
324+ ******************************************************************************/
325+static int BGPUpdatePathAttributeMPreachNLRI (u_int8_t *msg, ssize_t size, BGPUpdateInfo *bgpInfo)
326+{
327+ int ret;
328+ ssize_t len;
329+ BGPUpdateMRNLRI *pt;
330+ pt = (BGPUpdateMRNLRI *)msg;
331+ bgpInfo->PANLRIAFI = be16toh (pt->afi);
332+ bgpInfo->PANLRIAFIsub = pt->safi;
333+ len = (ssize_t)pt->len;
334+ ret = BGPMessagesAddress ((u_int8_t *)(pt+1)+len+1, size - (sizeof (BGPUpdateMRNLRI) + len + 1), &bgpInfo->PANLRIList, &bgpInfo->PANLRINum);
335+ if (ret==0 || ret <0) {
336+ bgpInfo->PANLRIAFI = 0;
337+ bgpInfo->PANLRIAFIsub = 0;
338+ return ret;
339+ }
340+
341+ return 1;
342+}
343+
344+/*******************************************************************************
345+ * Path attribute type 15: *****************************************************
346+ *
347+ ******************************************************************************/
348+static int BGPUpdatePathAttributeMPUnreachNLRI (u_int8_t *msg, ssize_t size, BGPUpdateInfo *bgpInfo)
349+{
350+ int ret;
351+ BGPUpdateMRUnNLRI *pt;
352+ pt = (BGPUpdateMRUnNLRI *)msg;
353+ bgpInfo->PAwithdrawnAFI = be16toh (pt->afi);
354+ bgpInfo->PAwithdrawnAFIsub = pt->safi;
355+ ret = BGPMessagesAddress ((u_int8_t *)(pt+1), size - sizeof (BGPUpdateMRUnNLRI), &bgpInfo->PAwithdrawnList, &bgpInfo->PAwithdrawnNum);
356+ if (ret==0 || ret <0) {
357+ bgpInfo->PAwithdrawnAFI = 0;
358+ bgpInfo->PAwithdrawnAFIsub = 0;
359+ return ret;
360+ }
361+
362+ return 1;
363+}
364+
365+/*******************************************************************************
366+ * BGP messages ****************************************************************
367+ *
368+ ******************************************************************************/
369+void freeBGPupdateInfo (BGPUpdateInfo *bgpInfo)
370+{
371+ if (bgpInfo->withdrawnList !=NULL) {free (bgpInfo->withdrawnList );}
372+ if (bgpInfo->PAPathList !=NULL) {free (bgpInfo->PAPathList );}
373+ if (bgpInfo->PANLRIList !=NULL) {free (bgpInfo->PANLRIList );}
374+ if (bgpInfo->PAwithdrawnList!=NULL) {free (bgpInfo->PAwithdrawnList);}
375+ if (bgpInfo->NLRIList !=NULL) {free (bgpInfo->NLRIList );}
376+}
377+
378+/*******************************************************************************
379+ * get BGP target Address ******************************************************
380+ *
381+ ******************************************************************************/
382+int BGPMessagesAddress (u_int8_t *area, ssize_t siz, struct NLRIInfo **List, int *num)
383+{
384+ struct NLRIInfo *pbuf, *pTmp;
385+ u_int8_t *pProc;
386+ ssize_t modSiz, prefixSiz;
387+
388+ pbuf = *List;
389+ if (area==NULL) {return 0;}
390+ else if (siz<2 ) {return 0;}
391+ pProc = area;
392+ modSiz = siz;
393+
394+ do {
395+ prefixSiz = ((int)*pProc)>>3;
396+ if ((((int)*pProc) & 0x7)!=0) {prefixSiz++;}
397+ if (modSiz<(prefixSiz+1)) {goto sizeError;}
398+ pTmp = (struct NLRIInfo *)realloc (pbuf, ((*num)+1) * sizeof (struct NLRIInfo));
399+ if (pTmp==NULL) {goto mallocError;}
400+ pbuf = pTmp;
401+
402+ (void) memset ((pbuf+(*num)), 0, sizeof (struct NLRIInfo));
403+ (void) memcpy (&(pbuf+(*num))->prefix, (pProc+1), prefixSiz);
404+ (pbuf+(*num))->prefixLen = (int)*pProc;
405+ (*num)++;
406+
407+#if DEBUG == 1 && 0
408+ printf ("prefixLen: %d, prefixSize: %d\n", (pbuf+(*num)-1)->prefixLen, prefixSiz);
409+ HEXoutput ((u_int8_t *)pbuf, (*num) * sizeof (struct NLRIInfo), 256);
410+#endif
411+
412+ pProc += (prefixSiz + 1);
413+ modSiz -= (prefixSiz + 1);
414+ } while (modSiz>0);
415+ if (modSiz<0) {goto sizeError;}
416+ *List = pbuf;
417+ return 1;
418+
419+ mallocError:
420+ sizeError:
421+ if (pbuf!=NULL) {free (pbuf);}
422+ return 0;
423+}
--- release/bmpStation-0.1/libbgp/Makefile.am (nonexistent)
+++ release/bmpStation-0.1/libbgp/Makefile.am (revision 6)
@@ -0,0 +1,11 @@
1+noinst_LIBRARIES = libbgp.a
2+include_HEADERS = bgp.h
3+libbgp_a_SOURCES = bgp.h getBGPmessages.c
4+libbgp_a_SOURCES +=
5+libbgp_a_SOURCES +=
6+libbgp_a_SOURCES +=
7+libbgp_a_SOURCES +=
8+libbgp_a_CFLAGS = -Wall -O2
9+libbgp_a_CFLAGS += -I./
10+libbgp_a_CFLAGS +=
11+libbgp_a_CFLAGS +=
--- release/bmpStation-0.1/bmpStation/bmpStationLib.c (nonexistent)
+++ release/bmpStation-0.1/bmpStation/bmpStationLib.c (revision 6)
@@ -0,0 +1,110 @@
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(BMP_STATION_H__)
29+# include <bmpStation.h>
30+#endif
31+#if !defined(BMP_STATION_INT_H__)
32+# include <bmpStationInt.h>
33+#endif
34+#if !defined(SELFLIB_H__)
35+# include <selfLib.h>
36+#endif
37+#if !defined(_STDIO_H) && !defined(_STDIO_H_)
38+# include <stdio.h>
39+#endif
40+#if !defined(_STDARG_H) && !defined(_STDARG_H_)
41+# include <stdarg.h>
42+#endif
43+#if !defined(_STRING_H) && !defined(_STRING_H_)
44+# include <string.h>
45+#endif
46+#if !defined(_STDLIB_H_) && !defined(_STDLIB_H)
47+# include <stdlib.h>
48+#endif
49+#if !defined(_SYS_TYPES_H_) && !defined(_SYS_TYPES_H)
50+# include <sys/types.h>
51+#endif
52+#if !defined(_SYS_STAT_H_) && !defined(_SYS_STAT_H)
53+# include <sys/stat.h>
54+#endif
55+#if !defined(_UNISTD_H) && !defined(_UNISTD_H_)
56+# include <unistd.h>
57+#endif
58+
59+
60+/*%''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''%**
61+ *: write Log :**
62+ *%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,%*/
63+
64+
65+/*******************************************************************************
66+ * syslog *********************************************************************/
67+void writeSystemLog (const u_int32_t lbl, const char *remote, const char *fmt, ...)
68+{
69+ FILE *wfd;
70+ char strdate[30];
71+ char *strLog;
72+ char *jmp, *ser;
73+ va_list ap;
74+ mode_t mode;
75+
76+ if (!FLGISSET(lastParam.loglevel, lbl)) {return ;}
77+ /*=Get Infomation===========================================================*/
78+ if (!dateLog(strdate , sizeof (strdate ))) {goto end_proc;}
79+ else if ((strLog=(char *)imalloc (LOGSTRMAX))==NULL) {goto end_proc;}
80+ /*=Get Log==================================================================*/
81+ va_start(ap, fmt);
82+ if (vsnprintf (strLog, LOGSTRMAX-1, fmt, ap)<0 ) {goto fin_va;}
83+ va_end(ap);
84+
85+ /*=Open File================================================================*/
86+ mode = umask (022);
87+ if ((wfd=fopen (syslogFile, "a"))==NULL) {goto free_data;}
88+ umask (mode);
89+
90+ /*=write Log================================================================*/
91+ ser = strLog;
92+ for (jmp=strstr (ser, "\n"); ; jmp=strstr (ser, "\n")) {
93+ if (jmp==NULL ) {}
94+ else if (*jmp=='\n') {*jmp = 0x00;}
95+ if (remote==NULL) {fprintf (wfd, "%s %s(%d): %s\n" , strdate, prgName, getpid (), strLog);}
96+ else {fprintf (wfd, "%s %s(%d): remote:%s %s\n", strdate, prgName, getpid (), remote, strLog);}
97+ if (jmp==NULL) {break;}
98+ ser = jmp + 1;
99+ }
100+ fclose (wfd);
101+
102+ return;
103+
104+ fin_va:
105+ va_end(ap);
106+ free_data:
107+ free (strLog);
108+ end_proc:
109+ return ;
110+}
--- release/bmpStation-0.1/bmpStation/bmpRead.c (nonexistent)
+++ release/bmpStation-0.1/bmpStation/bmpRead.c (revision 6)
@@ -0,0 +1,879 @@
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(BMP_STATION_H__)
29+# include <bmpStation.h>
30+#endif
31+#if !defined(BMP_STATION_INT_H__)
32+# include <bmpStationInt.h>
33+#endif
34+#if !defined(SELFLIB_H__)
35+# include <selfLib.h>
36+#endif
37+#if !defined(BMP_H__)
38+# include <bmp.h>
39+#endif
40+#if !defined(BGP_H__)
41+# include <bgp.h>
42+#endif
43+#if !defined(_ARPA_INET_H) && !defined(_ARPA_INET_H_)
44+# include <arpa/inet.h>
45+#endif
46+#if !defined(_NETINET_IN_H) && !defined(_NETINET_IN_H_)
47+# include <netinet/in.h>
48+#endif
49+#if !defined(_NETINET_TCP_H) && !defined(_NETINET_TCP_H_)
50+# include <netinet/tcp.h>
51+#endif
52+#if !defined(_SYS_SOCKET_H) && !defined(_SYS_SOCKET_H_)
53+# include <sys/socket.h>
54+#endif
55+#if !defined(_SYS_TYPES_H) && !defined(_SYS_TYPES_H_)
56+# include <sys/types.h>
57+#endif
58+#if !defined(_SYS_TIME_H) && !defined(_SYS_TIME_H_)
59+# include <sys/time.h>
60+#endif
61+#if !defined(_SYS_FILE_H) && !defined(_SYS_FILE_H_)
62+# include <sys/file.h>
63+#endif
64+#if !defined(_SYS_SELECT_H) && !defined(_SYS_SELECT_H_)
65+# include <sys/select.h>
66+#endif
67+#if !defined(_STRING_H) && !defined(_STRING_H_)
68+# include <string.h>
69+#endif
70+#if !defined(_UNISTD_H) && !defined(_UNISTD_H_)
71+# include <unistd.h>
72+#endif
73+#if !defined(_STDLIB_H) && !defined(_STDLIB_H_)
74+# include <stdlib.h>
75+#endif
76+#if !defined(_FCNTL_H) && !defined(_FCNTL_H_)
77+# include <fcntl.h>
78+#endif
79+#if !defined(_ERRNO_H) && !defined(_ERRNO_H_)
80+# include <errno.h>
81+#endif
82+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
83+#if !defined(_SYS_ENDIAN_H) && !defined(_SYS_ENDIAN_H_)
84+# include <sys/endian.h>
85+#endif
86+#else
87+#if !defined(_ENDIAN_H) && !defined(_ENDIAN_H_)
88+# include <endian.h>
89+#endif
90+#endif
91+
92+#if 1
93+#if !defined(_STDIO_H) && !defined(_STDIO_H_)
94+# include <stdio.h>
95+#endif
96+#endif
97+
98+
99+/*******************************************************************************
100+ * Global variables ***********************************************************/
101+static u_int8_t *pmsgStore; /* recv messages Data store */
102+static ssize_t imsgStoreSize; /* pmsgStore size */
103+static u_int8_t *pmsgBondStore; /* recv messages bondig Data store */
104+static u_int8_t *pmsgBondLast; /* pmsgBond 1st nodata point */
105+static u_int8_t *pmsgBondRead; /* pmsgBond read point */
106+static ssize_t iBondStoreSize; /* pmsgBondStore size */
107+static int soc4log;
108+/*=Peer infomation============================================================*/
109+#define NEW 1
110+#if NEW
111+char *pStrRemote = NULL;
112+#endif
113+
114+/*******************************************************************************
115+ * functions ******************************************************************/
116+
117+
118+/* old */
119+static void HEXoutput (u_int8_t *, int, int); /* debug code */
120+static void debugBMPinfo (BMPLogInfoSet *); /* debug code */
121+static int BMPRecvData (int);
122+#if 1
123+static int BMPv1Data (BMPLogInfoSet *, u_int8_t *, ssize_t);
124+static int BMPv3Data (BMPLogInfoSet *, u_int8_t *, ssize_t);
125+#else
126+static int BMPv1Data (u_int8_t *, ssize_t);
127+static int BMPv3Data (u_int8_t *, ssize_t);
128+#endif
129+
130+static int BMPInitiation (u_int8_t *, ssize_t);
131+static int BMPTermination (u_int8_t *, ssize_t);
132+static int BMPRouteMonitoring (BMPLogInfoSet *, u_int8_t *, ssize_t);
133+static int BMPRouteMonitoringLog (BMPLogInfoSet *, char *, u_int8_t *, ssize_t);
134+static int BMPStatisticsData (BMPLogInfoSet *, u_int8_t *, ssize_t);
135+static int BMPPeerDown (BMPLogInfoSet *, u_int8_t *, ssize_t, int);
136+static int BMPPeerUp (BMPLogInfoSet *, u_int8_t *, ssize_t, int);
137+
138+static int getBMPPeerAddr (BMPLogInfoSet *, char *, const int);
139+
140+/*******************************************************************************
141+ * main ***********************************************************************/
142+int bmpRead (int soc)
143+{
144+ int res;
145+ /* socket */
146+ int maxseg; /* TCP MSS size */
147+ int optlen; /* maxseg size */
148+ /* select */
149+ struct timeval itime, utime;
150+ int fdw , ret;
151+ fd_set iset , uset ; /* iset is initialize, uset for select */
152+
153+ /*=initialize===============================================================*/
154+ /* get Remote information */
155+ if ((pStrRemote = imalloc (NI_MAXHOST))==NULL) {
156+ if (FLGISSET(lastParam.loglevel, LOGLBL_STATS)) {
157+ writeLog (syslogFile, prgName, soc, "Fault memory allocate for remote hostname.");
158+ }
159+ }
160+ else if (!getRemoteHost (soc, pStrRemote, NI_MAXHOST)) {
161+ if (FLGISSET(lastParam.loglevel, LOGLBL_STATS)) {
162+ writeLog (syslogFile, prgName, soc, "Fault get remote hostname.");
163+ }
164+ goto free_remote_name;
165+ }
166+#if 1
167+ soc4log = soc;
168+#endif
169+ /* get TCP MSS size */
170+ optlen=sizeof(maxseg);
171+ if (getsockopt(soc,IPPROTO_TCP,TCP_MAXSEG, &maxseg, (socklen_t *)&optlen)<0) {
172+ writeSystemLog (LOGLBL_STATS, pStrRemote, "Fault get TCP MSS.");
173+ goto free_remote_name;
174+ }
175+ /* memory allocate imsgStore */
176+ imsgStoreSize = maxseg;
177+ if ((pmsgStore = malloc (imsgStoreSize))==NULL) {
178+ writeSystemLog (LOGLBL_STATS, pStrRemote, "Fault memory allocate for message store.");
179+ goto free_remote_name;
180+ }
181+ /* memory allocate imsgBondStore */
182+ iBondStoreSize = LIBBMP_MAXHEADERLEN + LIBBGP_MAXLENGTH + maxseg;
183+ if ((pmsgBondStore = imalloc (iBondStoreSize))==NULL) {
184+ writeSystemLog (LOGLBL_STATS, pStrRemote, "Fault memory allocate for message bond store.");
185+ free (pmsgStore);
186+ goto free_remote_name;
187+ }
188+ pmsgBondRead = pmsgBondLast = pmsgBondStore;
189+ /* select setup */
190+ fdw = 0;
191+ FD_ZERO(&iset);
192+ FD_SET(soc, &iset); fdw = soc;
193+ fdw++;
194+ (void) memset (&itime, 0, sizeof (struct timeval));
195+ itime = d2tval (10);
196+
197+ writeSystemLog (LOGLBL_STATS, pStrRemote, "Co-processes initialized.");
198+ /*=Read BMP data start======================================================*/
199+ while (1) {
200+ /*=setup==================================================================*/
201+ utime = itime; uset = iset;
202+ ret = select (fdw, &uset, NULL, NULL, &utime);
203+ if (ret< 0) {
204+ switch (errno) {
205+ case EINTR: continue; break;
206+ case EBADF: break;
207+ case EINVAL: break;
208+ case ENOMEM: break;
209+ }
210+ writeSystemLog (LOGLBL_STATS, pStrRemote, "select error.");
211+ goto free_memory;
212+ break;
213+ }
214+ else if (ret==0) {
215+ continue ;
216+ }
217+ else if (FD_ISSET(soc, &uset)) {
218+ res = BMPRecvData (soc);
219+ if (res==1) {}
220+ else if (res==0) {break;}
221+ else if (res <0) {goto free_memory;}
222+ }
223+ }
224+ /*=Read BMP data end========================================================*/
225+ writeSystemLog (LOGLBL_STATS, pStrRemote, "Termination.");
226+
227+ return 1;
228+
229+ free_memory:
230+ free (pmsgStore);
231+ free (pmsgBondStore);
232+
233+ free_remote_name:
234+ free (pStrRemote);
235+ return 0;
236+}
237+
238+/*******************************************************************************
239+ * Recv BMP data **************************************************************/
240+static int BMPRecvData (int soc)
241+{
242+ int readLen;
243+ int res;
244+ int iSize;
245+ /* BMP Log */
246+ BMPLogInfoSet BMPLogInfo;
247+ struct timeval localTime;
248+
249+ (void) memset (pmsgStore, 0, imsgStoreSize);
250+ /*=Read data================================================================*/
251+ readLen = recv (soc, pmsgStore, imsgStoreSize, MSG_DONTWAIT);
252+ if (readLen<0) {
253+ writeSystemLog (LOGLBL_STATS, pStrRemote, "BMP data recv error.");
254+ return -1;
255+ }
256+ else if (readLen > (iBondStoreSize-(pmsgBondLast - pmsgBondStore))) {
257+ writeSystemLog (LOGLBL_STATS, pStrRemote, "BMP data bonding store is not enough area.");
258+ return -1;
259+ }
260+ /*=Data Bonding=============================================================*/
261+ (void) memcpy (pmsgBondLast, pmsgStore, readLen); pmsgBondLast += readLen;
262+ pmsgBondRead = pmsgBondStore;
263+ do {
264+ /*=BMP data size check====================================================*/
265+ iSize = bmpMessageSizeCheck (pmsgBondRead, (ssize_t)(pmsgBondLast-pmsgBondRead));
266+ if (iSize==0) {break;}
267+ else if (iSize <0) {return -1;}
268+ /*=BMP Log Information====================================================*/
269+ (void) memset ((void *)&BMPLogInfo, 0, sizeof (BMPLogInfoSet));
270+ (void) memset ((char *)&localTime , 0, sizeof (struct timeval));
271+ if (gettimeofday (&localTime, NULL)<0) {
272+ writeSystemLog (LOGLBL_STATS, pStrRemote, "can't get time.");
273+ return -1;
274+ }
275+ BMPLogInfo.lcl_tv_sec = htobe32 (localTime.tv_sec);
276+ BMPLogInfo.lcl_tv_usec = htobe32 (localTime.tv_usec);
277+#if 0
278+ getBMPLogInfo (&BMPLogInfo, pmsgBondRead, iSize);
279+#endif
280+
281+ /*=get BMP data===========================================================*/
282+ switch (*(pmsgBondRead+0)) {
283+ case 1: res = BMPv1Data (&BMPLogInfo, pmsgBondRead, iSize); break;
284+ case 2: res = BMPv1Data (&BMPLogInfo, pmsgBondRead, iSize); break;
285+ case 3:
286+ res = BMPv3Data (&BMPLogInfo, pmsgBondRead, iSize);
287+ break;
288+ default:
289+ writeSystemLog (LOGLBL_STATS, pStrRemote, "recv can't understand data.");
290+ return -1;
291+ break;
292+ }
293+ if (res==0) {return 0;}
294+ else if (res <0) {return -1;}
295+#if 1
296+ printf ("iSize: %d\n", iSize);
297+ printf ("res : %d\n", res);
298+#endif
299+ pmsgBondRead += iSize;
300+ } while (pmsgBondRead<pmsgBondLast);
301+ (void) memcpy (pmsgBondStore, pmsgBondRead, (pmsgBondLast-pmsgBondRead));
302+ pmsgBondLast = pmsgBondStore + (pmsgBondLast - pmsgBondRead);
303+
304+ return 1;
305+}
306+/*%''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''%**
307+ *: get BMP data each version :**
308+ *%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,%*/
309+
310+/*******************************************************************************
311+ * BMP v1 data ****************************************************************/
312+static int BMPv1Data (BMPLogInfoSet *BMPLogInfo, u_int8_t *rdata, ssize_t dlen)
313+{
314+ /*=Variables================================================================*/
315+ int rsize;
316+ int res = 0;
317+ /* BMP */
318+ u_int8_t *msgData;
319+ BMPv1Header *BMPHeader;
320+
321+ /*=Init=====================================================================*/
322+ rsize = sizeof (BMPv1Header);
323+ if (dlen<rsize) {return 0;}
324+ BMPHeader = (BMPv1Header *)rdata;
325+ msgData = (u_int8_t *)(BMPHeader+1);
326+ /*=Format check=============================================================*/
327+ /* message type check */
328+ if (!bmpMessageTypeCheck (BMPHeader->version, BMPHeader->msgType)) {
329+ writeSystemLog (LOGLBL_STATS, pStrRemote, "recv can't understand the BMP message type.");
330+ return -1;
331+ }
332+ else if (!bmpPeerTypeCheck (BMPHeader->version, BMPHeader->peerType)) {
333+ writeSystemLog (LOGLBL_STATS, pStrRemote, "recv can't understand the BMP peer type.");
334+ return -1;
335+ }
336+
337+ /*=Recv Header==============================================================*/
338+ BMPLogInfo->version = BMPHeader->version;
339+ BMPLogInfo->msgType = BMPHeader->msgType;
340+ BMPLogInfo->peerType = BMPHeader->peerType;
341+ BMPLogInfo->peerFlags = BMPHeader->peerFlags;
342+ memcpy (&BMPLogInfo->peerDist, BMPHeader->peerDist, sizeof (((BMPLogInfoSet *)NULL)->peerDist));
343+ memcpy (&BMPLogInfo->peerAddr, BMPHeader->peerAddr, sizeof (((BMPLogInfoSet *)NULL)->peerAddr));
344+ BMPLogInfo->peerAS = BMPHeader->peerAS;
345+ BMPLogInfo->peerBgpID = BMPHeader->peerBgpID;
346+ BMPLogInfo->rtr_tv_sec = BMPHeader->tv_sec;
347+ BMPLogInfo->rtr_tv_usec = BMPHeader->tv_usec;
348+ BMPLogInfo->msgLen = htobe32 (sizeof (BMPLogInfoSet));
349+#if 1
350+ HEXoutput (pmsgBondRead, dlen, 256);
351+ debugBMPinfo (BMPLogInfo);
352+#endif
353+
354+ /*=Data Output==============================================================*/
355+ switch (BMPHeader->msgType) {
356+ case BMPV1MSGTYPE_ROUTEMON:
357+ res = BMPRouteMonitoring (BMPLogInfo, msgData, dlen - sizeof (BMPv1Header));
358+ break;
359+ case BMPV1MSGTYPE_STATISTICS:
360+ res = BMPStatisticsData (BMPLogInfo, msgData, dlen - sizeof (BMPv1Header));
361+ break;
362+ case BMPV1MSGTYPE_PEERDOWN:
363+ res = BMPPeerDown (BMPLogInfo, msgData, dlen - sizeof (BMPv1Header), BMPHeader->version);
364+ break;
365+ case BMPV1MSGTYPE_PEERUP:
366+ res = BMPPeerUp (BMPLogInfo, msgData, dlen - sizeof (BMPv1Header), BMPHeader->version);
367+ break;
368+ }
369+ if (res <0) {return -1;}
370+ else if (res==0) {return 1;}
371+ rsize+=res;
372+
373+ return 1;
374+}
375+
376+/*******************************************************************************
377+ * BMP v3 data ****************************************************************/
378+static int BMPv3Data (BMPLogInfoSet *BMPLogInfo, u_int8_t *rdata, ssize_t dlen)
379+{
380+ /*=Variables================================================================*/
381+ int rsize, hlen, msgLen;
382+ int res = 0;
383+ /* BMP */
384+ u_int8_t *msgData;
385+ BMPv3Header *BMPCommonHeader;
386+ BMPv3PerPeerHeader *BMPHeader;
387+
388+ /*=Init=====================================================================*/
389+#if 0
390+ HEXoutput (rdata, dlen, 256);
391+#endif
392+ hlen = rsize = sizeof (BMPv3Header);
393+ BMPCommonHeader = (BMPv3Header *)rdata;
394+ msgData = (u_int8_t *)(BMPCommonHeader+1);
395+ msgLen = be32toh (BMPCommonHeader->msgLen);
396+ /*=Format check=============================================================*/
397+#if 0
398+ HEXoutput (pmsgBondRead, dlen, 256);
399+ printf ("version : 0x%02x : 0x%08x : %d\n" , BMPCommonHeader->version , &BMPCommonHeader->version , sizeof (BMPCommonHeader->version));
400+ printf ("msgLen : %d : 0x%08x : %d, 0x%08x\n" , be32toh (BMPCommonHeader->msgLen) , &BMPCommonHeader->msgLen , sizeof (BMPCommonHeader->msgLen ), BMPCommonHeader->msgLen);
401+ printf ("msgType : 0x%02x : 0x%08x : %d\n" , BMPCommonHeader->msgType , &BMPCommonHeader->msgType , sizeof (BMPCommonHeader->msgType));
402+#endif
403+ /* message type check */
404+ if (!bmpMessageTypeCheck (BMPCommonHeader->version, BMPCommonHeader->msgType)) {
405+ writeSystemLog (LOGLBL_STATS, pStrRemote, "recv can't understand the BMP message type.");
406+ return -1;
407+ }
408+ switch (BMPCommonHeader->msgType) {
409+ case BMPV3MSGTYPE_INIT:
410+ res = BMPInitiation ((u_int8_t *)(BMPCommonHeader+1), msgLen - hlen);
411+ if (res <0) {
412+ writeSystemLog (LOGLBL_STATS, pStrRemote, "fault BMP initiation.");
413+ return -1;
414+ }
415+ else if (res==0) {return 1;}
416+ return 0;
417+ case BMPV3MSGTYPE_TERMINATE:
418+ if (!BMPTermination ((u_int8_t *)(BMPCommonHeader+1), msgLen - hlen)) {
419+ writeSystemLog (LOGLBL_STATS, pStrRemote, "fault BMP termination.");
420+ return -1;
421+ }
422+ return 0;
423+ break;
424+ default:
425+ break;
426+ }
427+
428+ hlen += sizeof (BMPv3PerPeerHeader);
429+ BMPHeader = (BMPv3PerPeerHeader *)msgData;
430+ msgData = (u_int8_t *)(BMPHeader+1);
431+ /* peer type check */
432+ if (!bmpPeerTypeCheck (BMPCommonHeader->version, BMPHeader->peerType)) {
433+ writeSystemLog (LOGLBL_STATS, pStrRemote, "recv can't understand the BMP peer type.");
434+ return -1;
435+ }
436+
437+ /*=Recv Header==============================================================*/
438+ BMPLogInfo->version = BMPCommonHeader->version;
439+ BMPLogInfo->msgLen = htobe32 (sizeof (BMPLogInfoSet));
440+ BMPLogInfo->msgType = BMPCommonHeader->msgType;
441+ BMPLogInfo->peerType = BMPHeader->peerType;
442+ BMPLogInfo->peerFlags = BMPHeader->peerFlags;
443+ memcpy (&BMPLogInfo->peerDist, BMPHeader->peerDist, sizeof (((BMPLogInfoSet *)NULL)->peerDist));
444+ memcpy (&BMPLogInfo->peerAddr, BMPHeader->peerAddr, sizeof (((BMPLogInfoSet *)NULL)->peerAddr));
445+ BMPLogInfo->peerAS = BMPHeader->peerAS;
446+ BMPLogInfo->peerBgpID = BMPHeader->peerBgpID;
447+ BMPLogInfo->rtr_tv_sec = BMPHeader->tv_sec;
448+ BMPLogInfo->rtr_tv_usec = BMPHeader->tv_usec;
449+
450+#if 1
451+ HEXoutput (pmsgBondRead, dlen, 256);
452+ debugBMPinfo (BMPLogInfo);
453+#endif
454+
455+ /*=Data Output==============================================================*/
456+ res = -1;
457+ switch (BMPCommonHeader->msgType) {
458+ case BMPV3MSGTYPE_ROUTEMON:
459+ res = BMPRouteMonitoring (BMPLogInfo, msgData, be32toh (BMPCommonHeader->msgLen)-hlen);
460+ break;
461+ case BMPV3MSGTYPE_STATISTICS:
462+ res = BMPStatisticsData (BMPLogInfo, msgData, be32toh (BMPCommonHeader->msgLen)-hlen);
463+ break;
464+ case BMPV3MSGTYPE_PEERDOWN:
465+ res = BMPPeerDown (BMPLogInfo, msgData, be32toh (BMPCommonHeader->msgLen)-hlen, BMPCommonHeader->version);
466+ break;
467+ case BMPV3MSGTYPE_PEERUP:
468+ res = BMPPeerUp (BMPLogInfo, msgData, be32toh (BMPCommonHeader->msgLen)-hlen, BMPCommonHeader->version);
469+ break;
470+ }
471+ if (res <0) {return -1;}
472+ else if (res==0) {return 1;}
473+
474+ return 1;
475+}
476+
477+/*%''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''%**
478+ *: get BMP message :**
479+ *%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,%*/
480+/*******************************************************************************
481+ * Route Monitoring ***********************************************************/
482+static int BMPRouteMonitoring (BMPLogInfoSet *BMPLogInfo, u_int8_t *rdata, ssize_t dlen)
483+{
484+ int rsize;
485+ BGPCommonHeader *BGPHeader;
486+ u_int8_t *msgData;
487+ char hostAddr[MAXPATHLEN];
488+
489+ rsize = sizeof (BGPCommonHeader);
490+ if (dlen<rsize) {return 0;}
491+ /*=Init=====================================================================*/
492+ BGPHeader = (BGPCommonHeader *)rdata;
493+ msgData = (u_int8_t *)(BGPHeader+1);
494+ rsize = be16toh(BGPHeader->length);
495+#if 0
496+ printf ("rsize(BGP headder): %d, 0x%04x\n", (int)rsize, rsize);
497+ printf ("dlen : %d\n", (int)dlen);
498+ HEXoutput (BGPHeader, rsize, 256);
499+#endif
500+ if (dlen < rsize) {return 0;}
501+ BMPLogInfo->msgLen = htobe32 (be32toh (BMPLogInfo->msgLen) + rsize);
502+#if 0
503+ printf ("pmsgBondStore : 0x%016x\n", (int)pmsgBondStore);
504+ printf ("BGPCommonHeader: 0x%016x\n", (int)BGPHeader);
505+ printf ("BGPLength : 0x%d\n" , (int)be16toh(BGPHeader->length));
506+ HEXoutput (rdata, (int)be16toh(BGPHeader->length), 256);
507+#endif
508+ /*=BGP Data Save============================================================*/
509+ getRemoteHost (soc4log, hostAddr, sizeof (hostAddr));
510+ if (!BMPRouteMonitoringLog (BMPLogInfo, hostAddr, rdata, rsize)) {
511+ return -1;
512+ }
513+
514+ return rsize;
515+}
516+
517+
518+/*******************************************************************************
519+ * Write Route monitor messages ***********************************************/
520+static int BMPRouteMonitoringLog (BMPLogInfoSet *BMPLogInfo, char *host, u_int8_t *rdata, ssize_t len)
521+{
522+ int wfd;
523+ int wlen, tlen;
524+ char routeMonitor[MAXPATHLEN];
525+ (void) memset (routeMonitor, 0, sizeof (routeMonitor));
526+ snprintf (routeMonitor, sizeof (routeMonitor)-1, "%s/%s.log", lastParam.workdir, host);
527+
528+ if ((wfd=open (routeMonitor, O_WRONLY|O_CREAT, 0644))<0) {return 0;}
529+ else if (flock (wfd, LOCK_EX)<0) {close (wfd); return 0;}
530+ else if (lseek(wfd, 0, SEEK_END)<0) {close (wfd); return 0;}
531+#if 0
532+ printf ("BMP LogInfo(bef): 0x%016x: tlen: %d\n", (int)BMPLogInfo, tlen);
533+ HEXoutput (BMPLogInfo, sizeof (BMPLogInfoSet), 256);
534+#endif
535+ wlen = tlen = write (wfd, (u_int8_t *)BMPLogInfo, sizeof (BMPLogInfoSet));
536+#if 0
537+ printf ("BMP LogInfo(aft): 0x%016x: tlen: %d\n", (int)BMPLogInfo, tlen);
538+ HEXoutput (BMPLogInfo, sizeof (BMPLogInfoSet), 256);
539+#endif
540+ if (tlen != sizeof (BMPLogInfoSet)) {
541+ flock (wfd, LOCK_UN);
542+ close (wfd);
543+ writeSystemLog (LOGLBL_STATS, pStrRemote, "Fault write BGP Monitor Data(BMP Info): %s", routeMonitor);
544+ return 0;
545+ }
546+ tlen = write (wfd, rdata, len);
547+#if 0
548+ printf ("BGP data : 0x%016x: tlen: %d\n", (int)rdata, tlen);
549+ HEXoutput (rdata, len, 256);
550+#endif
551+ wlen += tlen;
552+ if (tlen != len) {
553+ flock (wfd, LOCK_UN);
554+ close (wfd);
555+ writeSystemLog (LOGLBL_STATS, pStrRemote, "Fault write BGP Monitor Data(BMP Data): %s", routeMonitor);
556+ return 0;
557+ } else if (wlen != be32toh (BMPLogInfo->msgLen)) {
558+ flock (wfd, LOCK_UN);
559+ close (wfd);
560+ writeSystemLog (LOGLBL_STATS, pStrRemote, "Fault write BGP Monitor Data(Fault Data length): %s", routeMonitor);
561+ }
562+
563+ flock (wfd, LOCK_UN);
564+ close (wfd);
565+
566+ return 1;
567+}
568+
569+/*******************************************************************************
570+ * Stats Reports **************************************************************/
571+static int BMPStatisticsData (BMPLogInfoSet *BMPLogInfo, u_int8_t *rdata, ssize_t dlen)
572+{
573+ int rsize, i, num;
574+ u_int8_t *ptmp;
575+ BMPMsgStatsNum *StatsNum;
576+ BMPMsgStatsHeader *StatsHeader;
577+ BMPMsgStatsData *StatsData;
578+ char peerAddr[MAXPATHLEN];
579+ rsize = sizeof (BMPMsgStatsNum);
580+ if (dlen<rsize) {return 0;}
581+ /*=Init=====================================================================*/
582+ StatsNum = (BMPMsgStatsNum *)rdata;
583+ num = be32toh (*StatsNum);
584+ for (i=0; i<num; i++) {
585+ ptmp = rdata + rsize;
586+ rsize += sizeof (BMPMsgStatsHeader);
587+ if (dlen<rsize) {return 0;}
588+ StatsHeader = (BMPMsgStatsHeader *)ptmp;
589+ rsize += be16toh (StatsHeader->statLen);
590+ if (dlen<rsize) {return 0;}
591+ }
592+
593+#if 0
594+ printf ("BMP statistics data\n");
595+ printf ("rsize(BGP headder): %d\n", (int)rsize);
596+ printf ("dlen : %d\n", (int)dlen);
597+ HEXoutput (rdata, dlen, 256);
598+#endif
599+ getBMPPeerAddr (BMPLogInfo, peerAddr, sizeof (peerAddr));
600+ ptmp = (u_int8_t *)(StatsNum+1);
601+ for (i=0; i<num; i++) {
602+ StatsHeader = (BMPMsgStatsHeader *)ptmp;
603+ StatsData = (BMPMsgStatsData *)(StatsHeader+1);
604+ ptmp = (u_int8_t *)StatsData;
605+ ptmp += be16toh (StatsHeader->statLen);
606+ switch (be16toh (StatsHeader->statType)) {
607+ case BMPSTATSTYPE_REJECT_BY_INBOUND_POLICY:
608+ writeLog (statisticsFile, prgName, soc4log, "Adj-RIB-in: %s : # of prefixes rejected by inbound policy: %u", peerAddr, (int)be32toh (StatsData->count32));
609+ break;
610+ case BMPSTATSTYPE_DUPLICATE_ADVERTISEMENTS:
611+ writeLog (statisticsFile, prgName, soc4log, "Adj-RIB-in: %s : # of (known) duplicate prefix: %u", peerAddr, (int)be32toh (StatsData->count32));
612+ break;
613+ case BMPSTATSTYPE_DUPLICATE_WITHDRAWS:
614+ writeLog (statisticsFile, prgName, soc4log, "Adj-RIB-in: %s : # of (known) duplicate withdraws: %u", peerAddr, (int)be32toh (StatsData->count32));
615+ break;
616+ case BMPSTATSTYPE_UPDATES_INVALIDATED_CLUSTER:
617+ writeLog (statisticsFile, prgName, soc4log, "Adj-RIB-in: %s : # of updates invalidated due to CLUSTER_LIST loop: %u", peerAddr, (int)be32toh (StatsData->count32));
618+ break;
619+ case BMPSTATSTYPE_UPDATES_INVALIDATED_AS_PATH:
620+ writeLog (statisticsFile, prgName, soc4log, "Adj-RIB-in: %s : # of updates invalidated due to AS_PATH loop: %u", peerAddr, (int)be32toh (StatsData->count32));
621+ break;
622+ case BMPSTATSTYPE_UPDATES_INVALIDATED_ORIGIN:
623+ writeLog (statisticsFile, prgName, soc4log, "Adj-RIB-in: %s : # of updates invalidated due to ORIGINATOR_ID: %u", peerAddr, (int)be32toh (StatsData->count32));
624+ break;
625+ case BMPSTATSTYPE_UPDATES_INVALIDATED_AS_CONF:
626+ writeLog (statisticsFile, prgName, soc4log, "Adj-RIB-in: %s : # of updates invalidated due to AS_CONFED loop: %u", peerAddr, (int)be32toh (StatsData->count32));
627+ break;
628+ case BMPSTATSTYPE_ROUTES_ADJ_RIBs_IN:
629+ writeLog (statisticsFile, prgName, soc4log, "Adj-RIB-in: %s : # of routes in Adj-RIBs-In: %lu", peerAddr, (int)be64toh (StatsData->count64));
630+ break;
631+ case BMPSTATSTYPE_ROUTES_LOC_RIB:
632+ writeLog (statisticsFile, prgName, soc4log, "Adj-RIB-in: %s : # of routes in Loc-RIB: %lu", peerAddr, (int)be64toh (StatsData->count64));
633+ break;
634+ }
635+ }
636+ BMPLogInfo->msgLen += rsize;
637+
638+ return rsize;
639+}
640+
641+/*******************************************************************************
642+ * BGP Peer Down **************************************************************/
643+static int BMPPeerDown (BMPLogInfoSet *BMPLogInfo, u_int8_t *rdata, ssize_t dlen, int version)
644+{
645+ int rsize;
646+ BMPMsgPeerDown *BMPPeerDownHeader;
647+ BGPCommonHeader *BGPHeader;
648+ char peerAddr[MAXPATHLEN];
649+ rsize = sizeof (BMPMsgPeerDown);
650+ if (dlen<rsize) {return 0;}
651+ /*=Init=====================================================================*/
652+ BMPPeerDownHeader = (BMPMsgPeerDown *)rdata;
653+ getBMPPeerAddr (BMPLogInfo, peerAddr, sizeof (peerAddr));
654+ if (BMPPeerDownHeader->reason==4) {
655+ writeLog (peerEventLog, prgName, soc4log, "BGP Peer Down: %s", peerAddr);
656+ BMPLogInfo->msgLen += rsize;
657+ return rsize;
658+ }
659+ BGPHeader = (BGPCommonHeader *)(BMPPeerDownHeader+1);
660+ rsize += (int)be16toh (BGPHeader->length);
661+ if (dlen<rsize) {return 0;}
662+ else if (BGPHeader->type!=BGPMSGTYPE_NOTIFICATION) { /* sikp no target data */
663+ BMPLogInfo->msgLen += rsize;
664+ return rsize;
665+ }
666+ writeLog (peerEventLog, prgName, soc4log, "BGP Peer Down: %s", peerAddr);
667+
668+ return rsize;
669+}
670+
671+/*******************************************************************************
672+ * BGP Peer Up ****************************************************************/
673+static int BMPPeerUp (BMPLogInfoSet *BMPLogInfo, u_int8_t *rdata, ssize_t dlen, int version)
674+{
675+ int rsize;
676+ BGPCommonHeader *BGPHeader;
677+ BMPMsgPeerUp *BMPPeerUpHeader;
678+ u_int8_t *msgData;
679+ char peerAddr[MAXPATHLEN];
680+
681+ getBMPPeerAddr (BMPLogInfo, peerAddr, sizeof (peerAddr));
682+ if (BMPLogInfo->version==2) {
683+ rsize = sizeof (BGPCommonHeader);
684+ if (dlen<rsize) {return 0;}
685+ /*=Init===================================================================*/
686+ getBMPPeerAddr (BMPLogInfo, peerAddr, sizeof (peerAddr));
687+ BGPHeader = (BGPCommonHeader *)rdata;
688+ msgData = (u_int8_t *)(BGPHeader+1);
689+ if (dlen < be16toh(BGPHeader->length)) {return 0;}
690+ rsize = be16toh(BGPHeader->length);
691+ if (BGPHeader->type!=BGPMSGTYPE_OPEN) {return rsize;}
692+ writeLog (peerEventLog, prgName, soc4log, "BGP Peer Up: %s", peerAddr);
693+ BMPLogInfo->msgLen += rsize;
694+ return rsize;
695+ } else if (BMPLogInfo->version==3) {
696+#if 0
697+ printf ("rsize(BGP headder): %d\n", (int)rsize);
698+ printf ("dlen : %d\n", (int)dlen);
699+ HEXoutput (rdata, dlen, 256);
700+#endif
701+ BMPPeerUpHeader = (BMPMsgPeerUp *)rdata;
702+ writeLog (peerEventLog, prgName, soc4log, "BGP Peer Up: %s", peerAddr);
703+ return dlen;
704+ }
705+
706+ return -1;
707+}
708+
709+/*******************************************************************************
710+ * BMP Initiation Messages ****************************************************/
711+static int BMPInitiation (u_int8_t *rdata, ssize_t dlen)
712+{
713+ int psize;
714+ u_int8_t *ptmp;
715+ u_int8_t *pdata;
716+ int pdlen;
717+ BMPMsgInit *BMPInitMessage;
718+
719+ /*=Init=====================================================================*/
720+ ptmp = rdata;
721+ psize = dlen;
722+#if 0
723+ printf ("BMP Initiaion\n");
724+ HEXoutput (rdata, dlen, 256);
725+#endif
726+
727+ /*=Main proc================================================================*/
728+ do {
729+ BMPInitMessage = (BMPMsgInit *)ptmp;
730+ pdlen = be16toh (BMPInitMessage->infoLen);
731+ ptmp += pdlen + sizeof (BMPMsgInit);;
732+ psize -= pdlen + sizeof (BMPMsgInit);;
733+ if ((pdata=malloc (pdlen+1))==NULL) {
734+ writeSystemLog (LOGLBL_STATS, pStrRemote, "Fault memory allocate for BMP initiaion.");
735+ return -1;
736+ }
737+#if 0
738+ printf ("type : %d\n", be16toh (BMPInitMessage->infoType));
739+#endif
740+ (void) memset (pdata, 0, pdlen+1);
741+ (void) memcpy (pdata, (BMPInitMessage+1), pdlen);
742+ switch (be16toh (BMPInitMessage->infoType)) {
743+ case BMPINITMSG_STRING:
744+ writeSystemLog (LOGLBL_STATS, pStrRemote, "BMP Initiaion: string\n %s", pdata);
745+ break;
746+ case BMPINITMSG_SYSDESCR:
747+ writeSystemLog (LOGLBL_STATS, pStrRemote, "BMP Initiaion: sysDescr\n %s", pdata);
748+ break;
749+ case BMPINITMSG_SYSNAME:
750+ writeSystemLog (LOGLBL_STATS, pStrRemote, "BMP Initiaion: sysName\n %s", pdata);
751+ break;
752+ default:
753+ writeSystemLog (LOGLBL_STATS, pStrRemote, "BMP Initiaion: can't understand messages\n");
754+ free (pdata);
755+ return -1;
756+ break;
757+ }
758+ free (pdata);
759+ } while (psize>0);
760+ if (psize<0) {
761+ writeSystemLog (LOGLBL_STATS, pStrRemote, "BMP initiation messages length error.");
762+ return -1;
763+ }
764+
765+ return dlen;
766+}
767+
768+/*******************************************************************************
769+ * BMP Termination Messages ***************************************************/
770+static int BMPTermination (u_int8_t *rdata, ssize_t dlen)
771+{
772+ int psize;
773+ u_int8_t *ptmp;
774+ u_int8_t *pdata;
775+ int pdlen;
776+ BMPMsgTerminate *BMPTermMessage;
777+
778+ /*=Init=====================================================================*/
779+ ptmp = rdata;
780+ psize = dlen;
781+#if 0
782+ printf ("BMP Termination\n");
783+ HEXoutput (rdata, dlen, 256);
784+ printf ("psize: %d\n", psize);
785+#endif
786+
787+ /*=Main proc================================================================*/
788+ do {
789+ BMPTermMessage = (BMPMsgTerminate *)ptmp;
790+ pdlen = be16toh (BMPTermMessage->infoLen);
791+ ptmp += pdlen + sizeof (BMPMsgTerminate);
792+ psize -= pdlen + sizeof (BMPMsgTerminate);
793+ printf ("pdlen: %d\n", pdlen);
794+ printf ("psize: %d\n\n", psize);
795+ if ((pdata=malloc (pdlen+1))==NULL) {
796+ writeSystemLog (LOGLBL_STATS, pStrRemote, "Fault memory allocate for BMP Termination.");
797+ return 0;
798+ }
799+#if 0
800+ printf ("type : %d\n", be16toh (BMPTermMessage->infoType));
801+#endif
802+ (void) memset (pdata, 0, pdlen+1);
803+ (void) memcpy (pdata, (BMPTermMessage+1), pdlen);
804+ switch (be16toh (BMPTermMessage->infoType)) {
805+ case BMPTERMMSG_STRING:
806+ writeSystemLog (LOGLBL_STATS, pStrRemote, "BMP Termination: string\n %s", pdata);
807+ break;
808+ case BMPTERMMSG_REASON:
809+ writeSystemLog (LOGLBL_STATS, pStrRemote, "BMP Termination: reason: %d", be16toh (*((u_int16_t *)pdata)));
810+ break;
811+ }
812+ free (pdata);
813+ } while (psize>0);
814+ if (psize<0) {
815+ writeSystemLog (LOGLBL_STATS, pStrRemote, "BMP Term messages length error.");
816+ return 0;
817+ }
818+
819+ return 1;
820+}
821+
822+
823+/*******************************************************************************
824+ * GET BMP peer address *******************************************************/
825+static int getBMPPeerAddr (BMPLogInfoSet *BMPLogInfo, char *pstr, const int size)
826+{
827+ struct in_addr *sin_addr;
828+ struct in6_addr *sin6_addr;
829+
830+ (void) memset (pstr, 0, size);
831+ sin_addr = (struct in_addr *)&BMPLogInfo->peerAddr[3];
832+ sin6_addr = (struct in6_addr *)&BMPLogInfo->peerAddr;
833+ if (FLGISSET(BMPLogInfo->peerFlags, BMPPEERFLG_VFLG_GET)) {
834+ inet_ntop (AF_INET6, sin6_addr, pstr, size);
835+ } else {
836+ inet_ntop (AF_INET, sin_addr, pstr, size);
837+ }
838+
839+ return 1;
840+}
841+
842+/*%''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''%**
843+ *: DEBUG CODE :**
844+ *%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,%*/
845+/*******************************************************************************
846+ * BMP Information output *****************************************************/
847+static void debugBMPinfo (BMPLogInfoSet *BMPLogInfo)
848+{
849+ printf ("version : 0x%02x\n" , BMPLogInfo->version );
850+ printf ("msgLen : %d \n" , be32toh (BMPLogInfo->msgLen) );
851+ printf ("msgType : 0x%02x\n" , BMPLogInfo->msgType );
852+ printf ("peerType : 0x%02x\n" , BMPLogInfo->peerType );
853+ printf ("peerFlags: 0x%02x\n" , BMPLogInfo->peerFlags );
854+ printf ("peerDist : \n" );
855+ printf ("peerAddr : \n" );
856+ printf ("peerAS : %d \n" , (int)be32toh (BMPLogInfo->peerAS));
857+ printf ("BGP ID : %u \n" , be32toh (BMPLogInfo->peerBgpID) );
858+ printf ("tv_sec : %u \n" , be32toh (BMPLogInfo->rtr_tv_sec) );
859+ printf ("tv_usec : %06u \n" , be32toh (BMPLogInfo->rtr_tv_usec));
860+}
861+
862+/*******************************************************************************
863+ * HEX Data output ************************************************************/
864+static void HEXoutput (u_int8_t *rdata, int len, int max)
865+{
866+ int i;
867+ int outLen;
868+ int counter = -16;
869+ outLen = (len<max?len:max);
870+
871+ printf ("len: %d, output: %d\n", len, outLen);
872+ for (i=0; i<outLen; i++) {
873+ if ((i%16)==0) {counter += 16; printf ("0x%04X:", counter);}
874+ if ((i%2)==0) {printf (" ");}
875+ printf ("%02x", rdata[i]);
876+ if ((i%16)==15) {printf ("\n");}
877+ }
878+ printf ("\n");
879+}
--- release/bmpStation-0.1/bmpStation/bmpStation.c (nonexistent)
+++ release/bmpStation-0.1/bmpStation/bmpStation.c (revision 6)
@@ -0,0 +1,572 @@
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(BMP_STATION_H__)
29+# include <bmpStation.h>
30+#endif
31+#if !defined(BMP_STATION_INT_H__)
32+# include <bmpStationInt.h>
33+#endif
34+#if !defined(SELFLIB_H__)
35+# include <selfLib.h>
36+#endif
37+#if !defined(_SYS_TYPES_H) && !defined(_SYS_TYPES_H_)
38+# include <sys/types.h>
39+#endif
40+#if !defined(_SYS_SELECT_H) && !defined(_SYS_SELECT_H_)
41+# include <sys/select.h>
42+#endif
43+#if !defined(_SYS_WAIT_H) && !defined(_SYS_WAIT_H_)
44+# include <sys/wait.h>
45+#endif
46+#if !defined(_SYS_SOCKET_H) && !defined(_SYS_SOCKET_H_)
47+# include <sys/socket.h>
48+#endif
49+#if !defined(_STDIO_H) && !defined(_STDIO_H_)
50+# include <stdio.h>
51+#endif
52+#if !defined(_UNISTD_H) && !defined(_UNISTD_H_)
53+# include <unistd.h>
54+#endif
55+#if !defined(_STDLIB_H) && !defined(_STDLIB_H_)
56+# include <stdlib.h>
57+#endif
58+#if !defined(_STRING_H) && !defined(_STRING_H_)
59+# include <string.h>
60+#endif
61+#if !defined(_SIGNAL_H) && !defined(_SIGNAL_H_)
62+# include <signal.h>
63+#endif
64+#if !defined(_ERRNO_H) && !defined(_ERRNO_H_)
65+# include <errno.h>
66+#endif
67+
68+/*******************************************************************************
69+ * variables ******************************************************************/
70+static int tsoc; /* TCP Listen socket ***************************/
71+
72+/*******************************************************************************
73+ * functions ******************************************************************/
74+static int opt_proc (int, char **);
75+static void usage ();
76+static void hangup (int);
77+static void wait_child (int);
78+
79+/*+==========================================================================+**
80+ *| hang up
81+ *+==========================================================================+*/
82+static void hangup (int pid)
83+{
84+ close (tsoc);
85+
86+ exit (0);
87+}
88+
89+
90+/*%''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''%**
91+ *: main process :**
92+ *%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,%*/
93+int main (int argc, char **argv)
94+{
95+ /*****************************************************************************
96+ * Variables ****************************************************************/
97+ pid_t pid;
98+ /* select */
99+ struct timeval itime, utime;
100+ int fdw , ret;
101+ fd_set iset , uset ; /* iset is initialize, uset for select */
102+ /* socket */
103+ int asoc; /* accept socket */
104+ /*****************************************************************************
105+ * option process ***********************************************************/
106+ if (!opt_proc (argc, argv)) {goto JUMP_OPT;}
107+
108+ if (FLGISSET(lastParam.flags, OPTFLAGDAEMONIZE)) {
109+ if (daemon (0, 0)<0) {
110+ if (FLGISSET(lastParam.loglevel, LOGLBL_STATS)) {
111+ writeLog (syslogFile, prgName, -1, "Fault daemonize");
112+ }
113+ goto JUMP_OPT;
114+ }
115+ if (FLGISSET(lastParam.loglevel, LOGLBL_STATS)) {
116+ writeLog (syslogFile, prgName, -1, "daemonize");
117+ }
118+ }
119+
120+ /*=Signal setup=============================================================*/
121+ if (signal (SIGHUP , hangup )==SIG_ERR) {
122+ if (FLGISSET(lastParam.loglevel, LOGLBL_STATS)) {writeLog (syslogFile, prgName, -1, "Failure signal setup: SIGHUP.");}
123+ goto JUMP_OPT;
124+ }
125+ else if (signal (SIGINT , hangup )==SIG_ERR) {
126+ if (FLGISSET(lastParam.loglevel, LOGLBL_STATS)) {writeLog (syslogFile, prgName, -1, "Failure signal setup: SIGINT.");}
127+ goto JUMP_OPT;
128+ }
129+ else if (signal (SIGTERM, hangup )==SIG_ERR) {
130+ if (FLGISSET(lastParam.loglevel, LOGLBL_STATS)) {writeLog (syslogFile, prgName, -1, "Failure signal setup: SIGTERM.");}
131+ goto JUMP_OPT;
132+ }
133+ else if (signal (SIGCHLD, wait_child)==SIG_ERR) {
134+ if (FLGISSET(lastParam.loglevel, LOGLBL_STATS)) {writeLog (syslogFile, prgName, -1, "Failure signal setup: SIGCHLD.");}
135+ goto JUMP_OPT;
136+ }
137+ if (FLGISSET(lastParam.loglevel, LOGLBL_STATS)) {
138+ writeLog (syslogFile, prgName, -1, "signal setup");
139+ }
140+ /*****************************************************************************
141+ * Socket Listen ************************************************************/
142+ /*=Socket open==============================================================*/
143+ if ((tsoc=lsocket (lastParam.host, lastParam.ports, SOCK_STREAM, 0))<0) {
144+ if (FLGISSET(lastParam.loglevel, LOGLBL_STATS)) {
145+ writeLog (syslogFile, prgName, -1, "fault listen socket open.");
146+ }
147+ goto JUMP_OPT;
148+ }
149+ if (FLGISSET(lastParam.loglevel, LOGLBL_STATS)) {
150+ writeLog (syslogFile, prgName, -1, "listen socket open.");
151+ }
152+ /*=Select setup=============================================================*/
153+ fdw = 0;
154+ FD_ZERO(&iset);
155+ FD_SET(tsoc, &iset); fdw = tsoc;
156+ fdw++;
157+ (void) memset (&itime, 0, sizeof (struct timeval));
158+ itime = d2tval (10);
159+
160+ /*=TCP Listen===============================================================*/
161+ while (1) {
162+ utime = itime; uset = iset;
163+ ret = select (fdw, &uset, NULL, NULL, &utime);
164+ if (ret< 0) {
165+ switch (errno) {
166+ case EBADF: break;
167+ case EINTR: continue; break;
168+ case EINVAL: break;
169+ case ENOMEM: break;
170+ }
171+ if (FLGISSET(lastParam.loglevel, LOGLBL_STATS)) {
172+ writeLog (syslogFile, prgName, -1, "select error.");
173+ }
174+ goto ERR_CLOSE_SOC;
175+ }
176+ else if (ret==0) {continue ;}
177+ else if (FD_ISSET(tsoc, &uset)) {
178+ /*=main BMP proc========================================================*/
179+ if ((asoc=accept (tsoc, NULL, NULL))<0) {
180+ switch (errno) {
181+ case EMFILE:
182+ if (FLGISSET(lastParam.loglevel, LOGLBL_STATS)) {
183+ writeLog (syslogFile, prgName, -1, "limit tcp session.");
184+ }
185+ case EINTR:
186+ continue;
187+ break;
188+ case ENOTSOCK: case EOPNOTSUPP: case EPROTO: case EINVAL:
189+ case EFAULT: case EBADF: case EWOULDBLOCK:
190+ case ECONNABORTED: case ENOBUFS: case ENOMEM:
191+ default:
192+ if (FLGISSET(lastParam.loglevel, LOGLBL_STATS)) {
193+ writeLog (syslogFile, prgName, -1, "Listen socket is error.");
194+ }
195+ goto ERR_CLOSE_SOC;
196+ }
197+ }
198+ if (FLGISSET(lastParam.loglevel, LOGLBL_STATS)) {
199+ writeLog (syslogFile, prgName, asoc, "TCP session is open.");
200+ }
201+
202+ pid = fork ();
203+ if (pid<0) {
204+ if (FLGISSET(lastParam.loglevel, LOGLBL_STATS)) {
205+ writeLog (syslogFile, prgName, asoc, "Fault new process(fork).");
206+ }
207+ close (asoc);
208+ goto ERR_CLOSE_SOC;
209+ }
210+ else if (pid==0) {
211+ /* main process */
212+ if (!bmpRead (asoc)) {
213+ close (asoc);
214+ _exit(1);
215+ }
216+ if (FLGISSET(lastParam.loglevel, LOGLBL_STATS)) {
217+ writeLog (syslogFile, prgName, asoc, "Close session.");
218+ }
219+ close (asoc);
220+ _exit (0);
221+ }
222+ close (asoc);
223+ }
224+ }
225+ /*=Finish Process===========================================================*/
226+ close (tsoc);
227+
228+ if (FLGISSET(lastParam.loglevel, LOGLBL_STATS)) {
229+ writeLog (syslogFile, prgName, -1, "Close processes.");
230+ }
231+
232+ return 0;
233+
234+ ERR_CLOSE_SOC:
235+ close (tsoc);
236+ JUMP_OPT:
237+ return 1;
238+}
239+
240+/*******************************************************************************
241+ * wait child *****************************************************************/
242+static void wait_child (int pid)
243+{
244+ pid_t _cpid;
245+#if 0
246+ int id;
247+#endif
248+
249+ _cpid = wait (NULL);
250+#if 0
251+ if (FLGISSET(loglevel, LOGLVLSTATES2)) {
252+ if (id<0) {/* error proc */}
253+ else {/* error proc */}
254+ }
255+#endif
256+ while (SIG_ERR==signal (SIGCHLD, wait_child)) {
257+ /* error proc */
258+ }
259+
260+}
261+
262+/*******************************************************************************
263+ * usage **********************************************************************/
264+static void usage ()
265+{
266+ char spaPad[MAXPATHLEN]; /* space padding */
267+ (void) memset (spaPad, 0 , sizeof (spaPad));
268+ (void) memset (spaPad, ' ', (strlen (prgName)<sizeof (spaPad)?strlen (prgName):sizeof (spaPad)-1));
269+ /*=Usage main===============================================================*/
270+ fprintf (stdout, "%s [\033[1m-H\033[0m] [\033[1m-d\033[0m|\033[1m-D\033[0m] ", prgName);
271+ fprintf (stdout, " [\033[1m-c\033[0m|\033[1m-C\033[0m] [\033[1m-e\033[0m|\033[1m-E\033[0m] [\033[1m-n\033[0m|\033[1m-N \033[4mListen address\033[0m\033[0m]\n");
272+ fprintf (stdout, "%s [\033[1m-P \033[4mListen Port\033[0m\033[0m] [\033[1m-W \033[4mWork dirctory\033[0m\033[0m]", spaPad);
273+ fprintf (stdout, " [\033[1m-A \033[4mAccept TCP Number\033[0m\033[0m]\n");
274+ fprintf (stdout, "%s -H : help(this display)\n", spaPad);
275+ fprintf (stdout, "%s -[D |d]: (set|unset) debug mode\n", spaPad);
276+ fprintf (stdout, "%s -[C |c]: (set|unset) debug mode\n", spaPad);
277+ fprintf (stdout, "%s -[E |e]: (set|unset) damonized mode\n", spaPad);
278+ fprintf (stdout, "%s -[N \033[4mListen address\033[0m\033[0m|n]: (set|unset) Listen address\n", spaPad);
279+ fprintf (stdout, "%s -[P \033[4mListen Port\033[0m\033[0m ]: set Listen Port\n", spaPad);
280+ fprintf (stdout, "%s -W \033[4mWork Directory\033[0m\033[0m : set Work directory\n", spaPad);
281+ fprintf (stdout, "%s -A \033[4mAccept TCP Number\033[0m\033[0m : set Accept TCP Number\n", spaPad);
282+
283+ exit (1);
284+}
285+
286+/*******************************************************************************
287+ * option processes ***********************************************************/
288+static int opt_proc (int argc, char **argv)
289+{
290+ int ch, rtn;
291+ char uhdir[MAXPATHLEN]; /* user home directory */
292+ char curdir[MAXPATHLEN]; /* current directory */
293+ char *ppname;
294+ mode_t wdirmode;
295+
296+ ppname = prgName = *argv;
297+ while ((ppname=strstr (ppname, "/"))!=NULL) {
298+ ppname++;
299+ if (prgName == (ppname-1)) {prgName = ppname;}
300+ else if (*(ppname - 2) != 92) {prgName = ppname;}
301+ }
302+ /*****************************************************************************
303+ * initialize ***************************************************************/
304+ wdirmode = 0755;
305+ (void) memset ((char *)uhdir , 0, sizeof (uhdir ));
306+ (void) memset ((char *)curdir , 0, sizeof (curdir ));
307+ (void) memset ((char *)&defParam , 0, sizeof (defParam ));
308+ (void) memset ((char *)&cfgParam , 0, sizeof (cfgParam ));
309+ (void) memset ((char *)&argParam , 0, sizeof (argParam ));
310+ (void) memset ((char *)&lastParam, 0, sizeof (lastParam));
311+ ruid = getuid (); /* real user */
312+ euid = geteuid (); /* exec user */
313+ if (getcwd (curdir, sizeof (curdir))==NULL) {
314+ fprintf (stderr, "Fault current dir\n");
315+ return 0;
316+ }
317+
318+ /*****************************************************************************
319+ * set default **************************************************************/
320+ FLGSET(defParam.enableConfigFlag, OPTENABLECFLAGLPORT);
321+ strncpy (defParam.ports, DEFLPORT, sizeof (((optionParam *)NULL)->ports)-1);
322+ snprintf (defParam.ports, sizeof (((optionParam *)NULL)->ports)-1, "%s", DEFLPORT);
323+
324+ FLGSET(defParam.enableConfigFlag, OPTENABLECFLAGLHOST);
325+ (void) memset (defParam.host, 0, sizeof (((optionParam *)NULL)->host));
326+ snprintf (defParam.host, sizeof (((optionParam *)NULL)->host)-1, "%s", DEFLHOST);
327+
328+ FLGSET(defParam.enableConfigFlag, OPTENABLECFLAGDEBUG); FLGCLR(defParam.flags, OPTFLAGDEBUG);
329+ FLGSET(defParam.enableConfigFlag, OPTENABLECFLAGCHROOT); FLGCLR(defParam.flags, OPTFLAGCHROOT);
330+ FLGSET(defParam.enableConfigFlag, OPTENABLECFLAGTCPACCEPTNUM);
331+ defParam.acceptNum = DEFTCPACCEPTNUM;
332+ FLGSET(defParam.enableConfigFlag, OPTENABLECFLAGLOGLEVEL);
333+ defParam.loglevel = DEFLOGLVL;
334+
335+ GetHomeDir (ruid, uhdir, sizeof (uhdir));
336+ FLGSET(defParam.enableConfigFlag, OPTENABLECFLAGWORKDIR);
337+ snprintf (defParam.workdir, sizeof (((optionParam *)NULL)->workdir)-1, "%s/%s", uhdir, DEFWORKDIR);
338+
339+
340+ /*****************************************************************************
341+ * argument process *********************************************************/
342+ while ((ch = getopt (argc, argv, "A:cCdDeEHl:nN:P:uU:W:"))!=-1) {
343+ switch (ch) {
344+ case 'l': /* set log level */
345+ if (FLGISSET(argParam.enableConfigFlag, OPTENABLECFLAGLOGLEVEL)) break;
346+ FLGSET(argParam.enableConfigFlag, OPTENABLECFLAGLOGLEVEL);
347+ defParam.loglevel = atoi (optarg);
348+ break;
349+ case 'D': /* set Debug */
350+ if (FLGISSET(argParam.enableConfigFlag, OPTENABLECFLAGDEBUG)) break;
351+ FLGSET(argParam.enableConfigFlag, OPTENABLECFLAGDEBUG);
352+ FLGSET(argParam.flags , OPTFLAGDEBUG);
353+ break;
354+ case 'd': /* unset Debug */
355+ if (FLGISSET(argParam.enableConfigFlag, OPTENABLECFLAGDEBUG)) break;
356+ FLGSET(argParam.enableConfigFlag, OPTENABLECFLAGDEBUG);
357+ FLGCLR(argParam.flags , OPTFLAGDEBUG);
358+ break;
359+ case 'C': /* set Chroot */
360+ if (FLGISSET(argParam.enableConfigFlag, OPTENABLECFLAGCHROOT)) break;
361+ FLGSET(argParam.enableConfigFlag, OPTENABLECFLAGCHROOT);
362+ FLGSET(argParam.flags , OPTFLAGCHROOT);
363+ break;
364+ case 'c': /* unset Chroot */
365+ if (FLGISSET(argParam.enableConfigFlag, OPTENABLECFLAGCHROOT)) break;
366+ FLGSET(argParam.enableConfigFlag, OPTENABLECFLAGCHROOT);
367+ FLGCLR(argParam.flags , OPTFLAGCHROOT);
368+ break;
369+ case 'N': /* set Hostname */
370+ if (FLGISSET(argParam.enableConfigFlag, OPTENABLECFLAGLHOST)) break;
371+ FLGSET(argParam.enableConfigFlag, OPTENABLECFLAGLHOST);
372+ strncpy (argParam.host, optarg, sizeof (((optionParam *)NULL)->host)-1);
373+ break;
374+ case 'n': /* unset Hostname */
375+ if (FLGISSET(argParam.enableConfigFlag, OPTENABLECFLAGLHOST)) break;
376+ FLGSET(argParam.enableConfigFlag, OPTENABLECFLAGLHOST);
377+ (void) memset (argParam.host, 0, sizeof (((optionParam *)NULL)->host));
378+ break;
379+ case 'P': /* set Service(Port Number) */
380+ if (FLGISSET(argParam.enableConfigFlag, OPTENABLECFLAGLPORT)) break;
381+ FLGSET(argParam.enableConfigFlag, OPTENABLECFLAGLPORT);
382+ strncpy (argParam.ports, optarg, sizeof (((optionParam *)NULL)->ports)-1);
383+ break;
384+ case 'W': /* set workdir */
385+ if (FLGISSET(argParam.enableConfigFlag, OPTENABLECFLAGWORKDIR)) break;
386+ FLGSET(argParam.enableConfigFlag, OPTENABLECFLAGWORKDIR);
387+ if (*optarg == '/') {
388+ strncpy (argParam.workdir, optarg, sizeof (((optionParam *)NULL)->workdir)-1);
389+ } else {
390+ snprintf (argParam.workdir, sizeof (((optionParam *)NULL)->workdir)-1, "%s/%s", curdir, optarg);
391+ }
392+ break;
393+ case 'E': /* set daemonize */
394+ if (FLGISSET(argParam.enableConfigFlag, OPTENABLECFLAGDAEMONIZE)) break;
395+ FLGSET(argParam.enableConfigFlag, OPTENABLECFLAGDAEMONIZE);
396+ FLGSET(argParam.flags , OPTFLAGDAEMONIZE);
397+ break;
398+ case 'e': /* unset daemonize */
399+ if (FLGISSET(argParam.enableConfigFlag, OPTENABLECFLAGDAEMONIZE)) break;
400+ FLGSET(argParam.enableConfigFlag, OPTENABLECFLAGDAEMONIZE);
401+ FLGCLR(argParam.flags , OPTFLAGDAEMONIZE);
402+ break;
403+ case 'A': /* set TCP Accept Number */
404+ if (FLGISSET(argParam.enableConfigFlag, OPTENABLECFLAGTCPACCEPTNUM)) break;
405+ FLGSET(argParam.enableConfigFlag, OPTENABLECFLAGTCPACCEPTNUM);
406+ argParam.acceptNum = atoi (optarg);
407+ break;
408+ case 'H': /* Help */
409+ default:
410+ usage ();
411+ return 0;
412+ break;
413+ }
414+ }
415+ argc -= optind;
416+ argv += optind;
417+
418+ /*****************************************************************************
419+ * Last Option **************************************************************/
420+ /*=debug Option=*/
421+ if (FLGISSET(argParam.enableConfigFlag, OPTENABLECFLAGDEBUG)) {
422+ FLGSET(lastParam.enableConfigFlag, OPTENABLECFLAGDEBUG);
423+ lastParam.flags |= argParam.flags & OPTFLAGDEBUG;
424+ } else if (FLGISSET(cfgParam.enableConfigFlag, OPTENABLECFLAGDEBUG)) {
425+ FLGSET(lastParam.enableConfigFlag, OPTENABLECFLAGDEBUG);
426+ lastParam.flags |= cfgParam.flags & OPTFLAGDEBUG;
427+ } else {
428+ lastParam.enableConfigFlag |= defParam.enableConfigFlag & OPTENABLECFLAGDEBUG;
429+ lastParam.flags |= defParam.flags & OPTFLAGDEBUG;
430+ }
431+ /*=chroot Option=*/
432+ if (FLGISSET(argParam.enableConfigFlag, OPTENABLECFLAGCHROOT)) {
433+ FLGSET(lastParam.enableConfigFlag, OPTENABLECFLAGCHROOT);
434+ lastParam.flags |= argParam.flags & OPTFLAGCHROOT;
435+ } else if (FLGISSET(cfgParam.enableConfigFlag, OPTENABLECFLAGCHROOT)) {
436+ FLGSET(lastParam.enableConfigFlag, OPTENABLECFLAGCHROOT);
437+ lastParam.flags |= cfgParam.flags & OPTFLAGCHROOT;
438+ } else {
439+ lastParam.enableConfigFlag |= defParam.enableConfigFlag & OPTENABLECFLAGCHROOT;
440+ lastParam.flags |= defParam.flags & OPTFLAGCHROOT;
441+ }
442+ /*=daemonize Option=*/
443+ if (FLGISSET(argParam.enableConfigFlag, OPTENABLECFLAGDAEMONIZE)) {
444+ FLGSET(lastParam.enableConfigFlag, OPTENABLECFLAGDAEMONIZE);
445+ lastParam.flags |= argParam.flags & OPTFLAGDAEMONIZE;
446+ } else if (FLGISSET(cfgParam.enableConfigFlag, OPTENABLECFLAGDAEMONIZE)) {
447+ FLGSET(lastParam.enableConfigFlag, OPTENABLECFLAGDAEMONIZE);
448+ lastParam.flags |= cfgParam.flags & OPTFLAGDAEMONIZE;
449+ } else {
450+ lastParam.enableConfigFlag |= defParam.enableConfigFlag & OPTENABLECFLAGDAEMONIZE;
451+ lastParam.flags |= defParam.flags & OPTFLAGDAEMONIZE;
452+ }
453+ /*=workdir Option=*/
454+ if (FLGISSET(argParam.enableConfigFlag, OPTENABLECFLAGWORKDIR)) {
455+ FLGSET(lastParam.enableConfigFlag, OPTENABLECFLAGWORKDIR);
456+ strncpy (lastParam.workdir, argParam.workdir, sizeof (((optionParam *)NULL)->workdir)-1);
457+ } else if (FLGISSET(cfgParam.enableConfigFlag, OPTENABLECFLAGWORKDIR)) {
458+ FLGSET(lastParam.enableConfigFlag, OPTENABLECFLAGWORKDIR);
459+ strncpy (lastParam.workdir, cfgParam.workdir, sizeof (((optionParam *)NULL)->workdir)-1);
460+ } else {
461+ lastParam.enableConfigFlag |= defParam.enableConfigFlag & OPTENABLECFLAGWORKDIR;
462+ strncpy (lastParam.workdir, defParam.workdir, sizeof (((optionParam *)NULL)->workdir)-1);
463+ }
464+ /*=host Option=*/
465+ if (FLGISSET(argParam.enableConfigFlag, OPTENABLECFLAGLHOST)) {
466+ FLGSET(lastParam.enableConfigFlag, OPTENABLECFLAGLHOST);
467+ strncpy (lastParam.host, argParam.host, sizeof (((optionParam *)NULL)->host)-1);
468+ } else if (FLGISSET(cfgParam.enableConfigFlag, OPTENABLECFLAGLHOST)) {
469+ FLGSET(lastParam.enableConfigFlag, OPTENABLECFLAGLHOST);
470+ strncpy (lastParam.host, cfgParam.host, sizeof (((optionParam *)NULL)->host)-1);
471+ } else {
472+ lastParam.enableConfigFlag |= defParam.enableConfigFlag & OPTENABLECFLAGLHOST;
473+ strncpy (lastParam.host, defParam.host, sizeof (((optionParam *)NULL)->host)-1);
474+ }
475+ /*=port Option=*/
476+ if (FLGISSET(argParam.enableConfigFlag, OPTENABLECFLAGLPORT)) {
477+ FLGSET(lastParam.enableConfigFlag, OPTENABLECFLAGLPORT);
478+ strncpy (lastParam.ports, argParam.ports, sizeof (((optionParam *)NULL)->ports)-1);
479+ } else if (FLGISSET(cfgParam.enableConfigFlag, OPTENABLECFLAGLPORT)) {
480+ FLGSET(lastParam.enableConfigFlag, OPTENABLECFLAGLPORT);
481+ strncpy (lastParam.ports, cfgParam.ports, sizeof (((optionParam *)NULL)->ports)-1);
482+ } else {
483+ lastParam.enableConfigFlag |= defParam.enableConfigFlag & OPTENABLECFLAGLPORT;
484+ strncpy (lastParam.ports, defParam.ports, sizeof (((optionParam *)NULL)->ports)-1);
485+ }
486+ /*=accept number Option=*/
487+ if (FLGISSET(argParam.enableConfigFlag, OPTENABLECFLAGTCPACCEPTNUM)) {
488+ FLGSET(lastParam.enableConfigFlag, OPTENABLECFLAGTCPACCEPTNUM);
489+ lastParam.acceptNum = argParam.acceptNum;
490+ } else if (FLGISSET(cfgParam.enableConfigFlag, OPTENABLECFLAGLPORT)) {
491+ FLGSET(lastParam.enableConfigFlag, OPTENABLECFLAGTCPACCEPTNUM);
492+ lastParam.acceptNum = cfgParam.acceptNum;
493+ } else {
494+ lastParam.enableConfigFlag |= defParam.enableConfigFlag & OPTENABLECFLAGTCPACCEPTNUM;
495+ lastParam.acceptNum = defParam.acceptNum;
496+ }
497+ /*=log level Option=*/
498+ if (FLGISSET(argParam.enableConfigFlag, OPTENABLECFLAGLOGLEVEL)) {
499+ FLGSET(lastParam.enableConfigFlag, OPTENABLECFLAGLOGLEVEL);
500+ lastParam.loglevel = argParam.loglevel;
501+ } else if (FLGISSET(cfgParam.enableConfigFlag, OPTENABLECFLAGLOGLEVEL)) {
502+ FLGSET(lastParam.enableConfigFlag, OPTENABLECFLAGLOGLEVEL);
503+ lastParam.loglevel = cfgParam.loglevel;
504+ } else {
505+ lastParam.enableConfigFlag |= defParam.enableConfigFlag & OPTENABLECFLAGLOGLEVEL;
506+ lastParam.loglevel = defParam.loglevel;
507+ }
508+
509+ /*****************************************************************************
510+ * Setup ********************************************************************/
511+ /*=Chuser===================================================================*/
512+ /*=Create workdir===========================================================*/
513+ if ((rtn=chkdir (lastParam.workdir, wdirmode))<0) {
514+ fprintf (stderr, "Can't access the workdir: %s", lastParam.workdir);
515+ return 0;
516+ }
517+ else if (rtn==1) {}
518+ else if ((rtn=mkdirs (lastParam.workdir, wdirmode))<0) {
519+ fprintf (stderr, "Can't create the workdir: %s", lastParam.workdir);
520+ return 0;
521+ }
522+ else if (rtn==0) {
523+ fprintf (stderr, "Can't create the workdir: %s", lastParam.workdir);
524+ return 0;
525+ }
526+ /*=Chroot workdir===========================================================*/
527+ if (FLGISSET(lastParam.flags, OPTFLAGCHROOT)) {
528+ if (chroot (lastParam.workdir)<0) {
529+ fprintf (stderr, "Can't chroot to workdir: %s", lastParam.workdir);
530+ return 0;
531+ }
532+ else if (chdir ("/")<0) {
533+ fprintf (stderr, "Can't change to workdir: %s", lastParam.workdir);
534+ return 0;
535+ }
536+ snprintf (lastParam.workdir, sizeof (((optionParam *)NULL)->workdir)-1, "/");
537+ }
538+ else if (chdir (lastParam.workdir)<0) {
539+ fprintf (stderr, "Can't change to workdir: %s", lastParam.workdir);
540+ return 0;
541+ }
542+ /*=System log===============================================================*/
543+ (void) memset (syslogFile , 0, sizeof (syslogFile ));
544+ (void) memset (statisticsFile, 0, sizeof (statisticsFile));
545+ (void) memset (peerEventLog , 0, sizeof (peerEventLog ));
546+ snprintf (syslogFile , sizeof (syslogFile )-1, "%s/%s", lastParam.workdir, DEFSYSLOG );
547+ snprintf (statisticsFile, sizeof (statisticsFile)-1, "%s/%s", lastParam.workdir, DEFSTATISTICSLOG);
548+ snprintf (peerEventLog , sizeof (peerEventLog )-1, "%s/%s", lastParam.workdir, DEFEVENTLOG );
549+
550+ if (FLGISSET(lastParam.flags, OPTFLAGDEBUG)) {
551+ printf ("real user = %d\n", ruid);
552+ printf ("exec user = %d\n", euid);
553+ printf ("debug : %d\n", FLGISSET(lastParam.flags, OPTFLAGDEBUG));
554+ printf ("chroot : %d\n", FLGISSET(lastParam.flags, OPTFLAGCHROOT));
555+ printf ("daemon : %d\n", FLGISSET(lastParam.flags, OPTFLAGDAEMONIZE));
556+ printf ("host : %s\n", lastParam.host);
557+ printf ("ports : %s\n", lastParam.ports);
558+ printf ("accept#: %d\n", lastParam.acceptNum);
559+ printf ("workdir: %s\n", lastParam.workdir);
560+ printf ("log : %s\n", syslogFile);
561+ printf ("stati : %s\n", statisticsFile);
562+ printf ("event : %s\n", peerEventLog);
563+ }
564+
565+ if (FLGISSET(lastParam.loglevel, LOGLBL_STATS)) {
566+ writeLog (syslogFile, prgName, -1, "initialize");
567+ }
568+
569+ return 1;
570+}
571+
572+
--- release/bmpStation-0.1/bmpStation/bmpStationInt.h (nonexistent)
+++ release/bmpStation-0.1/bmpStation/bmpStationInt.h (revision 6)
@@ -0,0 +1,102 @@
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+#if !defined(BMP_STATION_INT_H__)
26+#define BMP_STATION_INT_H__ 1
27+/*******************************************************************************
28+ * include ********************************************************************/
29+#if defined(HAVE_CONFIG_H)
30+# include <config.h>
31+#endif
32+#if !defined(_SYS_TYPES_H) && !defined(_SYS_TYPES_H_)
33+# include <sys/types.h>
34+#endif
35+#if !defined(_SYS_PARAM_H) && !defined(_SYS_PARAM_H_)
36+# include <sys/param.h>
37+#endif
38+#if !defined(_NETDB_H) && !defined(_NETDB_H_)
39+# include <netdb.h>
40+#endif
41+/*******************************************************************************
42+ * Define *********************************************************************/
43+#define LOGSTRMAX 512
44+#define DEFLHOST ""
45+#define DEFLPORT "11019"
46+#define DEFTCPACCEPTNUM 0
47+#define DEFLOGLVL 0x8
48+#define DEFWORKDIR ".bmpStation"
49+#define DEFSYSLOG "system.log"
50+#define DEFSTATISTICSLOG "statistics.log"
51+#define DEFEVENTLOG "peer_event.log"
52+/*#define DEFBGPMONLOG "%H-%L_bgp.log"*/
53+
54+/*******************************************************************************
55+ * structure & typedef ********************************************************/
56+/*=option structure===========================================================*/
57+typedef struct {
58+ u_int64_t enableConfigFlag; /* active config flag */
59+#define OPTENABLECFLAGDEBUG 0x0000000000000001
60+#define OPTENABLECFLAGCHROOT 0x0000000000000002
61+#define OPTENABLECFLAGWORKDIR 0x0000000000000004
62+#define OPTENABLECFLAGLHOST 0x0000000000000008
63+#define OPTENABLECFLAGLPORT 0x0000000000000010
64+#define OPTENABLECFLAGTCPACCEPTNUM 0x0000000000000020
65+#define OPTENABLECFLAGLOGLEVEL 0x0000000000000040
66+#define OPTENABLECFLAGDAEMONIZE 0x0000000000000080
67+ u_int32_t flags; /* flag option */
68+#define OPTFLAGDEBUG 0x00000001
69+#define OPTFLAGCHROOT 0x00000002
70+#define OPTFLAGDAEMONIZE 0x00000004
71+ char workdir[MAXPATHLEN]; /* work directory */
72+ char host[NI_MAXHOST]; /* listen address */
73+ char ports[NI_MAXSERV]; /* listen service */
74+ int acceptNum; /* TCP accept Num */
75+ u_int32_t loglevel; /* log level */
76+#define LOGLBL_DEBUG 0x000001
77+#define LOGLBL_PACKET 0x000002
78+#define LOGLBL_NOTIFICATION 0x000004
79+#define LOGLBL_STATS 0x000008
80+} optionParam;
81+
82+/*******************************************************************************
83+ * variables ******************************************************************/
84+/*=System=====================================================================*/
85+char *prgName; /* arg program name ***********/
86+char pname[32]; /* program name ***************/
87+uid_t ruid; /* Real user id ***************/
88+uid_t euid; /* Exec user id ***************/
89+char syslogFile[MAXPATHLEN]; /* Proc system log ************/
90+char statisticsFile[MAXPATHLEN]; /* Statistics log *************/
91+char peerEventLog[MAXPATHLEN]; /* Peer event log *************/
92+/*=Options====================================================================*/
93+optionParam defParam;
94+optionParam cfgParam;
95+optionParam argParam;
96+optionParam lastParam;
97+/*******************************************************************************
98+ * functions ******************************************************************/
99+int bmpRead (int);
100+void writeSystemLog (const u_int32_t, const char *, const char *, ...);
101+
102+#endif
--- release/bmpStation-0.1/bmpStation/Makefile.am (nonexistent)
+++ release/bmpStation-0.1/bmpStation/Makefile.am (revision 6)
@@ -0,0 +1,13 @@
1+bin_PROGRAMS = bmpStation
2+bmpStation_SOURCES = bmpStationInt.h bmpStation.c bmpRead.c bmpStationLib.c
3+bmpStation_SOURCES +=
4+bmpStation_SOURCES +=
5+bmpStation_SOURCES +=
6+bmpStation_CFLAGS = -O2 -Wall -I../include -L../lib -I../libbmp -L../libbmp -I../libbgp -L../libbgp
7+bmpStation_CFLAGS +=
8+bmpStation_CFLAGS += -fno-strict-aliasing
9+bmpStation_CFLAGS +=
10+bmpStation_LDADD = -lbmp -lbgp -lself
11+bmpStation_LDADD +=
12+bmpStation_LDFLAGS =
13+bmpStation_LDFLAGS +=
--- release/bmpStation-0.1/bmpAnalysis/bmpAnalysis.c (nonexistent)
+++ release/bmpStation-0.1/bmpAnalysis/bmpAnalysis.c (revision 6)
@@ -0,0 +1,611 @@
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(BMP_STATION_H__)
29+# include <bmpStation.h>
30+#endif
31+#if !defined(BMP_ANALYSIS_H__)
32+# include <bmpAnalysis.h>
33+#endif
34+#if !defined(BMP_H__)
35+# include <bmp.h>
36+#endif
37+#if !defined(BGP_H__)
38+# include <bgp.h>
39+#endif
40+#if !defined(SELFLIB_H__)
41+# include <selfLib.h>
42+#endif
43+#if !defined(_STDIO_H) && !defined(_STDIO_H_)
44+# include <stdio.h>
45+#endif
46+#if !defined(_STDLIB_H) && !defined(_STDLIB_H_)
47+# include <stdlib.h>
48+#endif
49+#if !defined(_STRING_H) && !defined(_STRING_H_)
50+# include <string.h>
51+#endif
52+#if !defined(_UNISTD_H) && !defined(_UNISTD_H_)
53+# include <unistd.h>
54+#endif
55+#if !defined(_FCNTL_H) && !defined(_FCNTL_H_)
56+# include <fcntl.h>
57+#endif
58+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
59+#if !defined(_SYS_ENDIAN_H) && !defined(_SYS_ENDIAN_H_)
60+# include <sys/endian.h>
61+#endif
62+#else
63+#if !defined(_ENDIAN_H) && !defined(_ENDIAN_H_)
64+# include <endian.h>
65+#endif
66+#endif
67+#if !defined(_SYS_SOCKET_H) && !defined(_SYS_SOCKET_H_)
68+# include <sys/socket.h>
69+#endif
70+#if !defined(_NETINET_IN_H) && !defined(_NETINET_IN_H_)
71+# include <netinet/in.h>
72+#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
79+
80+
81+
82+#if 0
83+
84+
85+#if !defined(_SYS_SELECT_H) && !defined(_SYS_SELECT_H_)
86+# include <sys/select.h>
87+#endif
88+#if !defined(_SYS_WAIT_H) && !defined(_SYS_WAIT_H_)
89+# include <sys/wait.h>
90+#endif
91+#if !defined(_SIGNAL_H) && !defined(_SIGNAL_H_)
92+# include <signal.h>
93+#endif
94+#if !defined(_ERRNO_H) && !defined(_ERRNO_H_)
95+# include <errno.h>
96+#endif
97+#endif
98+
99+/*******************************************************************************
100+ * functions ******************************************************************/
101+static int bmpDataAnalyse (u_int8_t *, ssize_t);
102+static int opt_proc (int, char **);
103+static void selectOptionFlag32 (u_int64_t, u_int32_t, optionParam *, optionParam *, optionParam *, optionParam *);
104+static void selectOptionString (u_int64_t, ssize_t, void *, optionParam *, optionParam *, optionParam *, optionParam *);
105+static void usage ();
106+
107+/*******************************************************************************
108+ * HEX Data output ************************************************************/
109+static void HEXoutput (u_int8_t *rdata, int len, int max)
110+{
111+ int i;
112+ int outLen;
113+ int counter = -16;
114+ outLen = (len<max?len:max);
115+
116+ printf ("len: %d, output: %d\n", len, outLen);
117+ for (i=0; i<outLen; i++) {
118+ if ((i%16)==0) {counter += 16; printf ("0x%04X:", counter);}
119+ if ((i%2)==0) {printf (" ");}
120+ printf ("%02x", rdata[i]);
121+ if ((i%16)==15) {printf ("\n");}
122+ }
123+ printf ("\n");
124+}
125+
126+
127+/*%''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''%**
128+ *: main process :**
129+ *%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,%*/
130+int main (int argc, char **argv)
131+{
132+ /*****************************************************************************
133+ * Variables ****************************************************************/
134+ FILE *output;
135+ int rlog, rlen, rtn;
136+ ssize_t iBondStoreSize; /* pmsgStore size */
137+ u_int8_t *pmsgBondStore; /* read messages bondig Data store */
138+ u_int8_t *pmsgBondLast; /* pmsgBond 1st nodata point */
139+ u_int8_t *pmsgBondRead; /* pmsgBond read point */
140+ BMPLogInfoSet *pbmpLogHeader; /* pbmpLogHeader is Log Header Point */
141+
142+ /*****************************************************************************
143+ * option process ***********************************************************/
144+ if (!opt_proc (argc, argv)) {goto JUMP_OPT;}
145+ /*****************************************************************************
146+ * initialze ****************************************************************/
147+ output = stdout;
148+ iBondStoreSize = LIBBMP_MAXHEADERLEN + LIBBGP_MAXLENGTH;
149+ if ((pmsgBondStore = imalloc (iBondStoreSize))==NULL) {
150+ fprintf (stderr, "can't allocation stored area\n");
151+ goto JUMP_OPT;
152+ }
153+ pmsgBondRead = pmsgBondLast = pmsgBondStore;
154+ /*=Open file================================================================*/
155+ rlog = open (lastParam.logfile, O_RDONLY);
156+ if (rlog < 0) {
157+ fprintf (stderr, "can't open %s\n", lastParam.logfile);
158+ goto free_store;
159+ } else if (flock (rlog, LOCK_SH)<0) {
160+ fprintf (stderr, "can't lock %s\n", lastParam.logfile);
161+ goto open_log;
162+ }
163+
164+ /*****************************************************************************
165+ * Read file ****************************************************************/
166+ while ((rlen=read (rlog, pmsgBondLast, (iBondStoreSize-(pmsgBondLast-pmsgBondStore))))>=0) {
167+ int datVal;
168+ pmsgBondLast += rlen;
169+ pmsgBondRead = pmsgBondStore;
170+ datVal = pmsgBondLast-pmsgBondRead;
171+ if (FLGISSET(lastParam.enaFlag, OPTENAFLGDEBUG) && FLGISSET(lastParam.flags, OPTFLGDEBUG) && 0) {
172+ HEXoutput (pmsgBondStore, datVal, 256);
173+ }
174+
175+ while (datVal >= sizeof (BMPLogInfoSet)) {
176+ pbmpLogHeader = (BMPLogInfoSet *)pmsgBondRead;
177+ if (datVal < be32toh (pbmpLogHeader->msgLen)) {break;}
178+
179+ /* data analysis */
180+ rtn = bmpDataAnalyse ((u_int8_t *)pbmpLogHeader, be32toh (pbmpLogHeader->msgLen));
181+
182+
183+ pmsgBondRead += be32toh (pbmpLogHeader->msgLen);
184+ datVal = pmsgBondLast-pmsgBondRead;
185+ }
186+
187+ if (rlen==0) {break;}
188+ (void) memcpy (pmsgBondStore, pmsgBondRead, (pmsgBondLast-pmsgBondRead));
189+ pmsgBondLast = pmsgBondStore + (pmsgBondLast - pmsgBondRead);
190+ }
191+ if (rlen<0) {
192+ fprintf (stderr, "file read error.\n");
193+ goto open_log;
194+ }
195+
196+ flock (rlog, LOCK_UN);
197+ close (rlog);
198+ free (pmsgBondStore);
199+
200+ return 0;
201+
202+ open_log:
203+ close (rlog);
204+ free_store:
205+ free (pmsgBondStore);
206+ JUMP_OPT:
207+ return 1;
208+}
209+
210+/*******************************************************************************
211+ * usage **********************************************************************/
212+static void usage ()
213+{
214+ char spaPad[MAXPATHLEN]; /* space padding */
215+ (void) memset (spaPad, 0 , sizeof (spaPad));
216+ (void) memset (spaPad, ' ', (strlen (prgName)<sizeof (spaPad)?strlen (prgName):sizeof (spaPad)-1));
217+ /*=Usage main===============================================================*/
218+ fprintf (stdout, "%s [\033[1m-H\033[0m] [\033[1m-d\033[0m|\033[1m-D\033[0m] ", prgName);
219+ fprintf (stdout, " \033[1m-r \033[4mlog file\033[0m\033[0m\n");
220+#if 0
221+ fprintf (stdout, "%s [\033[1m-P \033[4mListen Port\033[0m\033[0m] [\033[1m-W \033[4mWork dirctory\033[0m\033[0m]", spaPad);
222+ fprintf (stdout, " [\033[1m-A \033[4mAccept TCP Number\033[0m\033[0m]\n");
223+#endif
224+ fprintf (stdout, "%s -H : help(this display)\n", spaPad);
225+ fprintf (stdout, "%s -[D |d]: (set|unset) debug mode\n", spaPad);
226+ fprintf (stdout, "%s -r \033[4mlog file\033[0m\033[0m : set log file\n", spaPad);
227+#if 0
228+ fprintf (stdout, "%s -[C |c]: (set|unset) debug mode\n", spaPad);
229+ fprintf (stdout, "%s -[E |e]: (set|unset) damonized mode\n", spaPad);
230+ fprintf (stdout, "%s -[N \033[4mListen address\033[0m\033[0m|n]: (set|unset) Listen address\n", spaPad);
231+ fprintf (stdout, "%s -[P \033[4mListen Port\033[0m\033[0m ]: set Listen Port\n", spaPad);
232+ fprintf (stdout, "%s -A \033[4mAccept TCP Number\033[0m\033[0m : set Accept TCP Number\n", spaPad);
233+#endif
234+
235+ exit (1);
236+}
237+
238+/*%''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''%**
239+ *: Data Analyse :**
240+ *%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,%*/
241+static int tval2str (struct timeval tv, char *str, ssize_t siz)
242+{
243+ time_t t;
244+ struct tm *date;
245+ char strBuf[32];
246+ t = tv.tv_sec;
247+ date = localtime (&t);
248+ (void) memset (strBuf, 0, sizeof (strBuf));
249+ strftime (strBuf, sizeof (strBuf), "%Y/%m/%d %H:%M:%S", date);
250+ snprintf (str, siz, "%s.%03ld", strBuf, tv.tv_usec/1000);
251+
252+ return 1;
253+}
254+
255+#if 0
256+static int msgAddr (u_int8_t *data, char *str, ssize_t siz, int aft)
257+{
258+ union addrarea addr;
259+ int len, nb;
260+ char addrTmp[64];
261+ len = (int)*data;
262+ nb = (len >>3);
263+ if ((len&0x7)!=0) {nb++;}
264+ (void)memset ((char *)&addr, 0, sizeof (addr));
265+ (void)memset (addrTmp, 0, sizeof (addrTmp));
266+ memcpy (&addr, (data+1), nb);
267+
268+ inet_ntop (aft, &addr, addrTmp, sizeof (addrTmp));
269+ snprintf (str, siz, "%s/%d", addrTmp, len);
270+
271+ return nb+1;
272+}
273+#endif
274+
275+/*******************************************************************************
276+ * BMP Update Messages ********************************************************/
277+static int bgpUpdateMessage (BMPLogInfoSet *pbmp, BGPCommonHeader *pbgp)
278+{
279+ int i;
280+ BGPUpdateInfo bgpInfo;
281+ struct timeval rtrTime, rcvTime;
282+ char rtrStrTime[30], rcvStrTime[30];
283+ struct in_addr *sin_addr;
284+ struct in6_addr *sin6_addr;
285+ char peerAddr[64];
286+ 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
294+
295+ (void)memset (rtrStrTime, 0, sizeof (rtrStrTime));
296+ (void)memset (rcvStrTime, 0, sizeof (rcvStrTime));
297+ rtrTime.tv_sec = be32toh (pbmp->rtr_tv_sec);
298+ rtrTime.tv_usec = be32toh (pbmp->rtr_tv_usec);
299+ rcvTime.tv_sec = be32toh (pbmp->lcl_tv_sec);
300+ rcvTime.tv_usec = be32toh (pbmp->lcl_tv_usec);
301+ tval2str (rtrTime, rtrStrTime, sizeof (rtrStrTime));
302+ tval2str (rcvTime, rcvStrTime, sizeof (rcvStrTime));
303+
304+ (void) memset (peerAddr, 0, sizeof (peerAddr));
305+ sin_addr = (struct in_addr *)&pbmp->peerAddr[3];
306+ sin6_addr = (struct in6_addr *)&pbmp->peerAddr;
307+ if (FLGISSET(pbmp->peerFlags, BMP_PEERFLG_VFLG_IPv6)) {
308+ inet_ntop (AF_INET6, sin6_addr, peerAddr, sizeof (peerAddr));
309+ } else {
310+ inet_ntop (AF_INET, sin_addr, peerAddr, sizeof (peerAddr));
311+ }
312+
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+ }
327+ }
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+ }
364+
365+
366+
367+ freeBGPupdateInfo (&bgpInfo);
368+#if 0
369+#if 1
370+ if (lenPattr>0) {
371+ u_int8_t *pt;
372+ int len;
373+ pproc = (u_int8_t *)(plenPattr+1);
374+ pPAttr = (BGPUpdatePathAttr *)pproc;
375+ 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 {
418+ (void) memset (updateAddr, 0, sizeof (updateAddr));
419+
420+ if (FLGISSET(pbmp->peerFlags, BMP_PEERFLG_VFLG_IPv6)) {
421+ rtn = msgAddr (pproc, updateAddr, sizeof (updateAddr), AF_INET6);
422+ } else {
423+ rtn = msgAddr (pproc, updateAddr, sizeof (updateAddr), AF_INET);
424+ }
425+ BGPLen -= rtn;
426+ pproc += rtn;
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;}
430+ }
431+
432+#endif
433+#endif
434+
435+ return 1;
436+}
437+
438+/*******************************************************************************
439+ * BMP Data analyses **********************************************************/
440+static int bmpDataAnalyse (u_int8_t *bData, ssize_t size)
441+{
442+ int ret;
443+ BMPLogInfoSet *pbmpLogHeader; /* pbmpLogHeader is Log Header Point */
444+ BGPCommonHeader *pbgpHeader; /* pbgpHeader is BGP update message Point */
445+ pbmpLogHeader = (BMPLogInfoSet *)bData;
446+ pbgpHeader = (BGPCommonHeader *)(pbmpLogHeader+1);
447+ if (FLGISSET(lastParam.enaFlag, OPTENAFLGDEBUG) && FLGISSET(lastParam.flags, OPTFLGDEBUG) && 0) {
448+ HEXoutput ((u_int8_t *)pbmpLogHeader, be32toh (pbmpLogHeader->msgLen), 256);
449+ }
450+
451+ ret = -1;
452+ switch (pbgpHeader->type) {
453+ case BGP_MSGTYPE_UPDATE :
454+ ret = bgpUpdateMessage (pbmpLogHeader, pbgpHeader);
455+ break;
456+ case BGP_MSGTYPE_OPEN :
457+ case BGP_MSGTYPE_NOTIFICATION:
458+ case BGP_MSGTYPE_KEEPALIVE :
459+ break;
460+ default:
461+ return -1;
462+ break;
463+ }
464+ if (ret< 0) {return -1;}
465+ else if (ret==0) {return 0;}
466+
467+ return 1;
468+}
469+
470+
471+
472+/*%''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''%**
473+ *: Option processing :**
474+ *%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,%*/
475+/*******************************************************************************
476+ * option processes ***********************************************************/
477+static int opt_proc (int argc, char **argv)
478+{
479+ int ch;
480+ char *ppname;
481+
482+ ppname = prgName = *argv;
483+ while ((ppname=strstr (ppname, "/"))!=NULL) {
484+ ppname++;
485+ if (prgName == (ppname-1)) {prgName = ppname;}
486+ else if (*(ppname - 2) != 92) {prgName = ppname;}
487+ }
488+ /*****************************************************************************
489+ * initialize ***************************************************************/
490+ (void) memset ((char *)&defParam , 0, sizeof (defParam ));
491+ (void) memset ((char *)&cfgParam , 0, sizeof (cfgParam ));
492+ (void) memset ((char *)&argParam , 0, sizeof (argParam ));
493+ (void) memset ((char *)&lastParam, 0, sizeof (lastParam));
494+
495+ /*****************************************************************************
496+ * set default **************************************************************/
497+ /* brief mode */
498+ FLGSET(defParam.enaFlag, OPTENAFLGBRIEF);
499+ FLGSET(defParam.flags , OPTFLGBRIEF);
500+
501+#if 0 /* for example */
502+ FLGSET(defParam.enableConfigFlag, OPTENABLECFLAGLPORT);
503+ strncpy (defParam.ports, DEFLPORT, sizeof (((optionParam *)NULL)->ports)-1);
504+ snprintf (defParam.ports, sizeof (((optionParam *)NULL)->ports)-1, "%s", DEFLPORT);
505+
506+ FLGSET(defParam.enableConfigFlag, OPTENABLECFLAGDEBUG); FLGCLR(defParam.flags, OPTFLAGDEBUG);
507+ FLGSET(defParam.enableConfigFlag, OPTENABLECFLAGCHROOT); FLGCLR(defParam.flags, OPTFLAGCHROOT);
508+ FLGSET(defParam.enableConfigFlag, OPTENABLECFLAGTCPACCEPTNUM);
509+ defParam.acceptNum = DEFTCPACCEPTNUM;
510+ FLGSET(defParam.enableConfigFlag, OPTENABLECFLAGLOGLEVEL);
511+ defParam.loglevel = DEFLOGLVL;
512+#endif
513+
514+ /*****************************************************************************
515+ * argument process *********************************************************/
516+ while ((ch = getopt (argc, argv, "bBdDeHr:"))!=-1) {
517+ switch (ch) {
518+ case 'b': /* brief mode */
519+ if (FLGISSET(argParam.enaFlag, OPTENAFLGBRIEF)) break;
520+ FLGSET(argParam.enaFlag, OPTENAFLGBRIEF);
521+ FLGSET(argParam.flags , OPTFLGBRIEF);
522+ break;
523+ case 'B': /* extensive mode */
524+ if (FLGISSET(argParam.enaFlag, OPTENAFLGBRIEF)) break;
525+ FLGSET(argParam.enaFlag, OPTENAFLGBRIEF);
526+ FLGCLR(argParam.flags , OPTFLGBRIEF);
527+ break;
528+ case 'r': /* read file */
529+ if (FLGISSET(argParam.enaFlag, OPTENAFLGLOGFILE)) break;
530+ FLGSET(argParam.enaFlag, OPTENAFLGLOGFILE);
531+ strncpy (argParam.logfile, optarg, sizeof (((optionParam *)NULL)->logfile)-1);
532+ break;
533+ case 'D': /* set Debug mode */
534+ if (FLGISSET(argParam.enaFlag, OPTENAFLGDEBUG)) break;
535+ FLGSET(argParam.enaFlag, OPTENAFLGDEBUG);
536+ FLGSET(argParam.flags , OPTFLGDEBUG);
537+ break;
538+ case 'd': /* unset Debug mode */
539+ if (FLGISSET(argParam.enaFlag, OPTENAFLGDEBUG)) break;
540+ FLGSET(argParam.enaFlag, OPTENAFLGDEBUG);
541+ FLGCLR(argParam.flags , OPTFLGDEBUG);
542+ break;
543+ case 'H': /* Help */
544+ default:
545+ usage ();
546+ return 0;
547+ break;
548+ }
549+ }
550+ argc -= optind;
551+ argv += optind;
552+
553+ /*****************************************************************************
554+ * Last Option **************************************************************/
555+ /* debug option */
556+ selectOptionFlag32 (OPTENAFLGDEBUG, OPTFLGDEBUG, &lastParam, &defParam, &cfgParam, &argParam);
557+ /* breif option */
558+ selectOptionFlag32 (OPTENAFLGBRIEF, OPTFLGBRIEF, &lastParam, &defParam, &cfgParam, &argParam);
559+ /* log file */
560+ selectOptionString (OPTENAFLGLOGFILE, sizeof (((optionParam *)NULL)->logfile), &((optionParam *)NULL)->logfile, &lastParam, &defParam, &cfgParam, &argParam);
561+
562+ /*****************************************************************************
563+ * Check ********************************************************************/
564+ if (!FLGISSET(lastParam.enaFlag, OPTENAFLGLOGFILE)) {
565+ fprintf (stdout, "Need the target file\n");
566+ usage ();
567+ }
568+
569+ return 1;
570+}
571+
572+/*******************************************************************************
573+ * select option from get type for string *************************************/
574+static void selectOptionString (u_int64_t ena, ssize_t size, void *pnt, optionParam *last, optionParam *def, optionParam *cfg, optionParam *arg)
575+{
576+ char *lastStr;
577+ char *dataStr;
578+ lastStr = (char *)((u_int8_t *)last + (ssize_t)pnt);
579+ FLGCLR(last->enaFlag, ena);
580+ (void) memset (lastStr, 0, size);
581+ if (FLGISSET(arg->enaFlag, ena)) {
582+ FLGSET(last->enaFlag, ena);
583+ dataStr = (char *)((u_int8_t *)arg + (ssize_t)pnt);
584+ } else if (FLGISSET(cfg->enaFlag, ena)) {
585+ FLGSET(last->enaFlag, ena);
586+ dataStr = (char *)((u_int8_t *)cfg + (ssize_t)pnt);
587+ } else {
588+ last->enaFlag |= def->enaFlag & ena;
589+ dataStr = (char *)((u_int8_t *)def + (ssize_t)pnt);
590+ }
591+ strncpy (lastStr, dataStr, size-1);
592+}
593+
594+/*******************************************************************************
595+ * select option from get type for flag ***************************************/
596+static void selectOptionFlag32 (u_int64_t ena, u_int32_t tag, optionParam *last, optionParam *def, optionParam *cfg, optionParam *arg)
597+{
598+ FLGCLR(last->enaFlag, ena);
599+ FLGCLR(last->flags , tag);
600+ if (FLGISSET(arg->enaFlag, ena)) {
601+ FLGSET(last->enaFlag, ena);
602+ last->flags |= arg->flags & tag;
603+ } else if (FLGISSET(cfg->enaFlag, ena)) {
604+ FLGSET(last->enaFlag, ena);
605+ last->flags |= cfg->flags & tag;
606+ } else {
607+ last->enaFlag |= def->enaFlag & ena;
608+ last->flags |= def->flags & tag;
609+ }
610+}
611+
--- release/bmpStation-0.1/bmpAnalysis/bmpAnalysis.h (nonexistent)
+++ release/bmpStation-0.1/bmpAnalysis/bmpAnalysis.h (revision 6)
@@ -0,0 +1,82 @@
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+#if !defined(BMP_ANALYSIS_H__)
26+#define BMP_ANALYSIS_H__ 1
27+/*******************************************************************************
28+ * include ********************************************************************/
29+#if defined(HAVE_CONFIG_H)
30+# include <config.h>
31+#endif
32+#if !defined(_SYS_TYPES_H) && !defined(_SYS_TYPES_H_)
33+# include <sys/types.h>
34+#endif
35+#if !defined(_SYS_PARAM_H) && !defined(_SYS_PARAM_H_)
36+# include <sys/param.h>
37+#endif
38+#if !defined(_NETDB_H) && !defined(_NETDB_H_)
39+# include <netdb.h>
40+#endif
41+/*******************************************************************************
42+ * Define *********************************************************************/
43+
44+/*******************************************************************************
45+ * Macro **********************************************************************/
46+
47+/*******************************************************************************
48+ * structure & typedef ********************************************************/
49+/*=option structure===========================================================*/
50+typedef struct {
51+ u_int64_t enaFlag; /* active config flag */
52+#define OPTENAFLGDEBUG 0x0000000000000001
53+#define OPTENAFLGLOGFILE 0x0000000000000002
54+#define OPTENAFLGBRIEF 0x0000000000000004
55+ u_int32_t flags; /* flag option */
56+#define OPTFLGDEBUG 0x00000001
57+#define OPTFLGBRIEF 0x00000002
58+#define OPTFLG 0x00000001
59+#define OPTFLG 0x00000001
60+#define OPTFLG 0x00000001
61+#define OPTFLG 0x00000001
62+ char logfile[MAXPATHLEN]; /* work directory */
63+} optionParam;
64+
65+/*******************************************************************************
66+ * variables ******************************************************************/
67+/*=System=====================================================================*/
68+char *prgName; /* arg program name ***********/
69+char pname[32]; /* program name ***************/
70+/*=Options====================================================================*/
71+optionParam defParam;
72+optionParam cfgParam;
73+optionParam argParam;
74+optionParam lastParam;
75+/*******************************************************************************
76+ * functions ******************************************************************/
77+#if 0
78+int bmpRead (int);
79+void writeSystemLog (const u_int32_t, const char *, const char *, ...);
80+#endif
81+
82+#endif
--- release/bmpStation-0.1/include/selfLib.h (nonexistent)
+++ release/bmpStation-0.1/include/selfLib.h (revision 6)
@@ -0,0 +1,86 @@
1+/* -*- c -*- */
2+/*-
3+ * The MIT License
4+ *
5+ * Copyright (c) 2014 Yuki SAKAI
6+ * All Rights Reserved.
7+ *
8+ * Permission is hereby granted, free of charge, to any person obtaining a
9+ * copy of this software and associated documentation files (the "Software"),
10+ * to deal in the Software without restriction, including without limitation
11+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12+ * and/or sell copies of the Software, and to permit persons to whom the
13+ * Software is furnished to do so, subject to the following conditions:
14+ *
15+ * The above copyright notice and this permission notice shall be included in
16+ * all copies or substantial portions of the Software.
17+ *
18+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24+ * IN THE SOFTWARE.
25+ */
26+/*******************************************************************************
27+ * include ********************************************************************/
28+
29+/*******************************************************************************
30+ * Personal system library
31+ ******************************************************************************/
32+#ifndef SELFLIB_H__
33+#define SELFLIB_H__ __DATE__
34+/*******************************************************************************
35+ * Include ********************************************************************/
36+#if !defined(_SYS_TYPES_H_) && !defined(_SYS_TYPES_H)
37+# include <sys/types.h>
38+#endif
39+#if !defined(_SYS_STAT_H) && !defined(_SYS_STAT_H_)
40+# include <sys/stat.h>
41+#endif
42+#if !defined(_NETDB_H) && !defined(_NETDB_H_)
43+# include <netdb.h>
44+#endif
45+#if !defined(_NETINET_IN_H) && !defined(_NETINET_IN_H_)
46+# include <netinet/in.h>
47+#endif
48+
49+/*******************************************************************************
50+ * Macro **********************************************************************/
51+#define FLGSET(a,b) (a|=b)
52+#define FLGISSET(a,b) ((a&b)==0?0:1)
53+#define FLGTGL(a,b) (a^=b)
54+#define FLGCLR(a,b) (a^=(a&b))
55+
56+
57+/*******************************************************************************
58+ * Structure & union **********************************************************/
59+
60+/*******************************************************************************
61+ * Functions ******************************************************************/
62+/*=memory=====================================================================*/
63+void *imalloc (size_t);
64+/*=Network====================================================================*/
65+int lsocket (const char *, const char *, int, int);
66+int getRemoteHost (const int, char *, const int);
67+/*=Time=======================================================================*/
68+struct timeval d2tval (double);
69+/*=pwd========================================================================*/
70+int GetHomeDir (uid_t, char *, ssize_t);
71+/*=path=======================================================================*/
72+ssize_t getLastPathBlock (const char *, char *, ssize_t);
73+int chkdir (const char *, mode_t);
74+int mkdirs (const char *, mode_t);
75+ssize_t rmPathLastBlock (char *);
76+ssize_t rmPathLastSlash (char *);
77+ssize_t packPathDupSlash (char *);
78+/*=log========================================================================*/
79+int dateLog (char *, const int);
80+void writeLog (const char *, const char *, const int, const char *, ...);
81+void writeSystemLog (const u_int32_t, const char *, const char *, ...);
82+
83+
84+
85+#endif
86+
--- release/bmpStation-0.1/include/bmpStation.h (nonexistent)
+++ release/bmpStation-0.1/include/bmpStation.h (revision 6)
@@ -0,0 +1,106 @@
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+#if !defined(BMP_STATION_H__)
26+#define BMP_STATION_H__ 1
27+/*******************************************************************************
28+ * include ********************************************************************/
29+#if defined(HAVE_CONFIG_H)
30+# include <config.h>
31+#endif
32+#if !defined(_SYS_TYPES_H) && !defined(_SYS_TYPES_H_)
33+# include <sys/types.h>
34+#endif
35+
36+/*******************************************************************************
37+ * Define *********************************************************************/
38+
39+/*******************************************************************************
40+ * Macro **********************************************************************/
41+
42+/*******************************************************************************
43+ * structure & typedef ********************************************************/
44+/*+==========================================================================+**
45+ *| BMP Station logging |**
46+ *+==========================================================================+*/
47+/*=BMP logging binary=========================================================**
48+ * save data is big endian
49+ * 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
50+ * 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
51+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
52+ * | Version | msg type | peer type | peer flags |
53+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
54+ * | msg length |
55+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
56+ * | Peer Distinguisher (8 Byte) |
57+ * | |
58+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
59+ * | Peer Address (16 Byte) |
60+ * | |
61+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
62+ * | Peer AS |
63+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
64+ * | Peer BGP ID |
65+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
66+ * | Router Timestamp (seconds) |
67+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
68+ * | Router Timestamp (microseconds) |
69+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70+ * | Local Timestamp (seconds) |
71+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
72+ * | Local Timestamp (microseconds) |
73+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
74+ * | messages data |
75+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
76+ ******************************************************************************/
77+#define TESTDATA 1
78+typedef struct {
79+ u_int8_t version;
80+#if TESTDATA == 1
81+ u_int32_t msgLen;
82+#endif
83+ u_int8_t msgType;
84+ u_int8_t peerType;
85+ u_int8_t peerFlags;
86+#if TESTDATA == 0
87+ u_int32_t msgLen;
88+#endif
89+ u_int32_t peerDist[2];
90+ u_int32_t peerAddr[4];
91+ u_int32_t peerAS;
92+ u_int32_t peerBgpID;
93+ u_int32_t rtr_tv_sec;
94+ u_int32_t rtr_tv_usec;
95+ u_int32_t lcl_tv_sec;
96+ u_int32_t lcl_tv_usec;
97+} __attribute__((__packed__)) BMPLogInfoSet;
98+
99+/*******************************************************************************
100+ * variables ******************************************************************/
101+
102+/*******************************************************************************
103+ * functions ******************************************************************/
104+
105+
106+#endif
--- release/bmpStation-0.1/include/config.h.in (nonexistent)
+++ release/bmpStation-0.1/include/config.h.in (revision 6)
@@ -0,0 +1,25 @@
1+/* include/config.h.in. Generated from configure.in by autoheader. */
2+
3+/* Name of package */
4+#undef PACKAGE
5+
6+/* Define to the address where bug reports for this package should be sent. */
7+#undef PACKAGE_BUGREPORT
8+
9+/* Define to the full name of this package. */
10+#undef PACKAGE_NAME
11+
12+/* Define to the full name and version of this package. */
13+#undef PACKAGE_STRING
14+
15+/* Define to the one symbol short name of this package. */
16+#undef PACKAGE_TARNAME
17+
18+/* Define to the home page for this package. */
19+#undef PACKAGE_URL
20+
21+/* Define to the version of this package. */
22+#undef PACKAGE_VERSION
23+
24+/* Version number of package */
25+#undef VERSION
--- release/bmpStation-0.1/Makefile.am (nonexistent)
+++ release/bmpStation-0.1/Makefile.am (revision 6)
@@ -0,0 +1 @@
1+SUBDIRS = libbmp libbgp lib bmpStation bmpAnalysis
--- release/bmpStation-0.1/configure.in (nonexistent)
+++ release/bmpStation-0.1/configure.in (revision 6)
@@ -0,0 +1,59 @@
1+# -*- Autoconf -*-
2+# Process this file with autoconf to produce a configure script.
3+
4+AC_PREREQ([2.63])
5+AC_INIT(bmpStation, 0.1.0, y.sakai@arteria-net.com)
6+AC_CONFIG_SRCDIR([bmpStation/bmpStationInt.h])
7+AC_CONFIG_HEADERS([include/config.h])
8+AC_PROG_RANLIB
9+
10+# Checks for programs.
11+AC_PROG_CC
12+AM_PROG_CC_C_O
13+AM_INIT_AUTOMAKE
14+
15+################################################################################
16+# Default LIBS/Include
17+saved_LIBS="$LIBS"
18+saved_CFLAGS="$CFLAGS"
19+if test -d "/usr/local" ; then
20+ LIBS="$saved_LIBS -L/usr/local/lib" ; saved_LIBS="$LIBS"
21+ CFLAGS="$saved_CFLAGS -I/usr/local/include"; saved_CFLAGS="$CFLAGS"
22+fi
23+if test -d "/usr/pkg" ; then
24+ LIBS="$saved_LIBS -L/usr/pkg/lib" ; saved_LIBS="$LIBS"
25+ CFLAGS="$saved_CFLAGS -I/usr/pkg/include"; saved_CFLAGS="$CFLAGS"
26+fi
27+
28+
29+################################################################################
30+# Checks for Options(enable)
31+dnl AC_ARG_ENABLE(debug,
32+dnl [ --enable-debug turn on debugging [[default=no]]],
33+dnl [\
34+dnl case "${enableval}" in
35+dnl yes) enable_debug=yes ;;
36+dnl no) enable_debug=no ;;
37+dnl *) AC_MSG_ERROR(bad value for --enable-debug) ;;
38+dnl esac],
39+dnl enable_debug=no)
40+dnl if test x"${enable_debug}" = x"yes"; then
41+dnl AC_DEFINE(DEBUG, 1, [Define to 1 if you want to debug])
42+dnl fi
43+
44+################################################################################
45+# Enable and With process
46+dnl if test x"$with_gmp" != x"yes" ; then
47+dnl LIBS="$saved_LIBS -L$with_gmp/lib" ; saved_LIBS="$LIBS"
48+dnl CFLAGS="$saved_CFLAGS -I$with_gmp/include"; saved_CFLAGS="$CFLAGS"
49+dnl fi
50+
51+CPPFLAGS="$CFLAGS"
52+################################################################################
53+AC_CONFIG_FILES([Makefile
54+ libbgp/Makefile
55+ libbmp/Makefile
56+ lib/Makefile
57+ bmpStation/Makefile
58+ bmpAnalysis/Makefile])
59+AC_OUTPUT
--- release/bmpStation-0.1/lib/time.c (nonexistent)
+++ release/bmpStation-0.1/lib/time.c (revision 6)
@@ -0,0 +1,55 @@
1+/* -*- c -*- */
2+/*-
3+ * The MIT License
4+ *
5+ * Copyright (c) 2014 Yuki SAKAI
6+ * All Rights Reserved.
7+ *
8+ * Permission is hereby granted, free of charge, to any person obtaining a
9+ * copy of this software and associated documentation files (the "Software"),
10+ * to deal in the Software without restriction, including without limitation
11+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12+ * and/or sell copies of the Software, and to permit persons to whom the
13+ * Software is furnished to do so, subject to the following conditions:
14+ *
15+ * The above copyright notice and this permission notice shall be included in
16+ * all copies or substantial portions of the Software.
17+ *
18+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24+ * IN THE SOFTWARE.
25+ */
26+
27+/*******************************************************************************
28+ * include ********************************************************************/
29+#if !defined(SELFLIB_H__)
30+# include <selfLib.h>
31+#endif
32+#if !defined(_STRING_H) && !defined(_STRING_H_)
33+# include <string.h>
34+#endif
35+#if defined(__NetBSD__) || defined(__OpenBSD__)
36+#if !defined(_TIME_H) && !defined(_TIME_H_)
37+# include <time.h>
38+#endif
39+#elif defined(__linux__)
40+#if !defined(_SYS_TIME_H) && !defined(_SYS_TIME_H_)
41+# include <sys/time.h>
42+#endif
43+#endif
44+
45+/*******************************************************************************
46+ * Transration from double to timeval *****************************************/
47+struct timeval d2tval (double td)
48+{
49+ struct timeval tv;
50+ (void) memset ((char *)&tv, 0, sizeof (struct timeval));
51+ tv.tv_sec = (long)td;
52+ tv.tv_usec = (long)((td-(double)tv.tv_sec)*1e6);
53+ return tv;
54+}
55+
--- release/bmpStation-0.1/lib/Makefile.am (nonexistent)
+++ release/bmpStation-0.1/lib/Makefile.am (revision 6)
@@ -0,0 +1,18 @@
1+noinst_LIBRARIES = libbmpStation.a libself.a
2+include_HEADERS = ../include/bmpStation.h ../include/selfLib.h
3+libself_a_SOURCES =../include/selfLib.h memory.c network.c path.c time.c pwd.c log.c
4+libself_a_SOURCES += option.c
5+libself_a_SOURCES +=
6+libself_a_CFLAGS = -Wall -O2
7+libself_a_CFLAGS += -I../include -I../libbgp -L../libbgp -I../libbmp -L../libbmp
8+libself_a_CFLAGS +=
9+libself_a_CFLAGS +=
10+libbmpStation_a_SOURCES = ../bmpStation.h
11+libbmpStation_a_SOURCES +=
12+libbmpStation_a_SOURCES +=
13+libbmpStation_a_SOURCES +=
14+libbmpStation_a_SOURCES +=
15+libbmpStation_a_CFLAGS = -Wall -O2
16+libbmpStation_a_CFLAGS += -I../include -I../libbgp -L../libbgp -I../libbmp -L../libbmp
17+libbmpStation_a_CFLAGS +=
18+libbmpStation_a_CFLAGS +=
--- release/bmpStation-0.1/lib/option.c (nonexistent)
+++ release/bmpStation-0.1/lib/option.c (revision 6)
@@ -0,0 +1,41 @@
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+ * include ********************************************************************/
27+#if !defined(SELFLIB_H__)
28+# include <selfLib.h>
29+#endif
30+#if !defined(_SYS_TYPES_H) && !defined(_SYS_TYPES_H_)
31+# include <sys/types.h>
32+#endif
33+#if !defined(_STRING_H) && !defined(_STRING_H_)
34+# include <string.h>
35+#endif
36+
37+/*%''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''%**
38+ *: Option :**
39+ *%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,%*/
40+/*******************************************************************************
41+ * select options *************************************************************/
--- release/bmpStation-0.1/lib/network.c (nonexistent)
+++ release/bmpStation-0.1/lib/network.c (revision 6)
@@ -0,0 +1,113 @@
1+/* -*- c -*- */
2+/*
3+ * The MIT License
4+ *
5+ * Copyright (c) 2014 Yuki SAKAI
6+ * All Rights Reserved.
7+ *
8+ * Permission is hereby granted, free of charge, to any person obtaining a
9+ * copy of this software and associated documentation files (the "Software"),
10+ * to deal in the Software without restriction, including without limitation
11+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12+ * and/or sell copies of the Software, and to permit persons to whom the
13+ * Software is furnished to do so, subject to the following conditions:
14+ *
15+ * The above copyright notice and this permission notice shall be included in
16+ * all copies or substantial portions of the Software.
17+ *
18+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24+ * IN THE SOFTWARE.
25+ */
26+
27+/*******************************************************************************
28+ * include ********************************************************************/
29+#if !defined(SELFLIB_H__)
30+# include <selfLib.h>
31+#endif
32+#if !defined(_SYS_SOCKET_H) && !defined(_SYS_SOCKET_H_)
33+# include <sys/socket.h>
34+#endif
35+#if !defined(_SYS_TYPES_H) && !defined(_SYS_TYPES_H_)
36+# include <sys/types.h>
37+#endif
38+#if !defined(_STRING_H) && !defined(_STRING_H_)
39+# include <string.h>
40+#endif
41+#if !defined(_NETDB_H) && !defined(_NETDB_H_)
42+# include <netdb.h>
43+#endif
44+#if !defined(_UNISTD_H) && !defined(_UNISTD_H_)
45+# include <unistd.h>
46+#endif
47+#if !defined(_ARPA_INET_H_) && !defined(_ARPA_INET_H)
48+# include <arpa/inet.h>
49+#endif
50+#if !defined(_NETINET_IN_H) && !defined(_NETINET_IN_H_)
51+# include <netinet/in.h>
52+#endif
53+
54+
55+/*******************************************************************************
56+ * Listen socket functions (for IPv4 and IPv6 on TCP and UDP) *****************/
57+int lsocket (const char *hostname, const char *port, int stype, int accept)
58+{
59+ struct addrinfo soc_info, *psinfo;
60+ int soc = -1, ret = -1;
61+ long on = 1;
62+
63+ /*****************************************************************************
64+ * Init Information *********************************************************/
65+ (void) memset ((char *)&soc_info, 0, sizeof (struct addrinfo));
66+ if (hostname==(void *)0) {soc_info.ai_flags = AI_PASSIVE;}
67+ else if (strlen (hostname)<=0) {hostname = (void *)0; soc_info.ai_flags = AI_PASSIVE;}
68+ soc_info.ai_family = AF_UNSPEC;
69+ soc_info.ai_socktype = stype;
70+ /*=Socket Setup=============================================================*/
71+ if (getaddrinfo (hostname, port, &soc_info, &psinfo)!=0) {ret = -1; goto err_ret; }
72+ else if ((soc=socket (psinfo->ai_family, psinfo->ai_socktype, psinfo->ai_protocol))<0) {ret = -2; goto err_ret; }
73+ else if (bind (soc, psinfo->ai_addr, psinfo->ai_addrlen)<0) {ret = -3; goto err_close;}
74+ else if (stype==SOCK_DGRAM) {goto true_fin;}
75+ else if (listen (soc, accept)<0) {ret = -4; goto err_close;}
76+ true_fin:
77+ setsockopt(soc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
78+ freeaddrinfo (psinfo);
79+ return soc;
80+
81+ /*=Error Process============================================================*/
82+ err_close:
83+ close (soc);
84+ err_ret:
85+ freeaddrinfo (psinfo);
86+ return ret;
87+}
88+
89+/*******************************************************************************
90+ * Get Remote Host address ****************************************************/
91+int getRemoteHost (const int soc, char *pstr, const int size)
92+{
93+ struct sockaddr_storage hostAddr;
94+ socklen_t namelen;
95+ struct sockaddr_in *ppF;
96+ struct sockaddr_in6 *ppS;
97+ (void) memset (pstr , 0, size);
98+ (void) memset (&hostAddr, 0, sizeof (struct sockaddr_storage));
99+ /*=Get IP address ==========================================================*/
100+ namelen = sizeof (struct sockaddr_storage);
101+ if (getpeername (soc, (struct sockaddr *)&hostAddr, &namelen)<0) {return 0;}
102+ if (hostAddr.ss_family == AF_INET) {
103+ ppF = (struct sockaddr_in *)&hostAddr;
104+ inet_ntop (AF_INET, &ppF->sin_addr, pstr, size);
105+ }
106+ else if (hostAddr.ss_family == AF_INET6) {
107+ ppS = (struct sockaddr_in6 *)&hostAddr;
108+ inet_ntop (AF_INET6, &ppS->sin6_addr, pstr, size);
109+ }
110+ else {return 0;}
111+
112+ return 1;
113+}
--- release/bmpStation-0.1/lib/pwd.c (nonexistent)
+++ release/bmpStation-0.1/lib/pwd.c (revision 6)
@@ -0,0 +1,51 @@
1+/* -*- c -*- */
2+/*
3+ * The MIT License
4+ *
5+ * Copyright (c) 2014 Yuki SAKAI
6+ * All Rights Reserved.
7+ *
8+ * Permission is hereby granted, free of charge, to any person obtaining a
9+ * copy of this software and associated documentation files (the "Software"),
10+ * to deal in the Software without restriction, including without limitation
11+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12+ * and/or sell copies of the Software, and to permit persons to whom the
13+ * Software is furnished to do so, subject to the following conditions:
14+ *
15+ * The above copyright notice and this permission notice shall be included in
16+ * all copies or substantial portions of the Software.
17+ *
18+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24+ * IN THE SOFTWARE.
25+ */
26+
27+/*******************************************************************************
28+ * Include ********************************************************************/
29+#if !defined(SELFLIB_H__)
30+# include <selfLib.h>
31+#endif
32+#if !defined(_SYS_TYPES_H_) && !defined(_SYS_TYPES_H)
33+# include <sys/types.h>
34+#endif
35+#if !defined(_PWD_H) && !defined(_PWD_H_)
36+# include <pwd.h>
37+#endif
38+#if !defined(_STRING_H) && !defined(_STRING_H_)
39+# include <string.h>
40+#endif
41+
42+/*******************************************************************************
43+ * Get Homedir From UID *******************************************************/
44+int GetHomeDir (uid_t uid, char *buf, ssize_t blen)
45+{
46+ struct passwd *pwd;
47+ if ((pwd=getpwuid (uid))==(void *)0) {endpwent (); return -1;}
48+ strncpy (buf, pwd->pw_dir, (blen-1));
49+ endpwent ();
50+ return 1;
51+}
--- release/bmpStation-0.1/lib/libbmpStation.h (nonexistent)
+++ release/bmpStation-0.1/lib/libbmpStation.h (revision 6)
@@ -0,0 +1,55 @@
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+#if !defined(__BMP_STATION_H__)
26+#define __BMP_STATION_H__ 1
27+
28+/*******************************************************************************
29+ * include ********************************************************************/
30+#if !defined(_SYS_TYPES_H) && !defined(_SYS_TYPES_H_)
31+# include <sys/types.h>
32+#endif
33+#if !defined(_SYS_TIME_H) && !defined(_SYS_TIME_H_)
34+# include <sys/time.h>
35+#endif
36+
37+/*******************************************************************************
38+ * Define *********************************************************************/
39+
40+/*******************************************************************************
41+ * Macro **********************************************************************/
42+
43+/*******************************************************************************
44+ * structure & typedef ********************************************************/
45+
46+/*******************************************************************************
47+ * variables ******************************************************************/
48+/*******************************************************************************
49+ * functions ******************************************************************/
50+int BMPRecvData (int, u_int8_t **, ssize_t *);
51+
52+#endif
53+
54+
55+
--- release/bmpStation-0.1/lib/path.c (nonexistent)
+++ release/bmpStation-0.1/lib/path.c (revision 6)
@@ -0,0 +1,172 @@
1+/* -*- c -*- */
2+/*
3+ * The MIT License
4+ *
5+ * Copyright (c) 2014 Yuki SAKAI
6+ * All Rights Reserved.
7+ *
8+ * Permission is hereby granted, free of charge, to any person obtaining a
9+ * copy of this software and associated documentation files (the "Software"),
10+ * to deal in the Software without restriction, including without limitation
11+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12+ * and/or sell copies of the Software, and to permit persons to whom the
13+ * Software is furnished to do so, subject to the following conditions:
14+ *
15+ * The above copyright notice and this permission notice shall be included in
16+ * all copies or substantial portions of the Software.
17+ *
18+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24+ * IN THE SOFTWARE.
25+ */
26+
27+/*******************************************************************************
28+ * Include ********************************************************************/
29+#if !defined(SELFLIB_H__)
30+# include <selfLib.h>
31+#endif
32+#if !defined(_SYS_PARAM_H) && !defined(_SYS_PARAM_H_)
33+# include <sys/param.h>
34+#endif
35+#if !defined(_STRING_H) && !defined(_STRING_H_)
36+# include <string.h>
37+#endif
38+#if !defined(_SYS_STAT_H) && !defined(_SYS_STAT_H_)
39+# include <sys/stat.h>
40+#endif
41+#if !defined(_ERRNO_H) && !defined(_ERRNO_H_)
42+# include <errno.h>
43+#endif
44+
45+/*******************************************************************************
46+ * Get Last Block**************************************************************/
47+ssize_t getLastPathBlock (const char *dpath, char *lpath, ssize_t llen)
48+{
49+ const char *sp, *fp, *tp;
50+ /*=Search===================================================================*/
51+ sp = tp = dpath;
52+ for (fp=strstr (tp, "/"); fp!=NULL; fp=strstr (tp, "/")) {
53+ if (tp==fp ) {tp = fp + 1; sp = tp;}
54+ else if (*(fp-1)=='\\') {tp = fp + 1;}
55+ else {tp = fp + 1; sp = tp;}
56+ }
57+ /*=Copy=====================================================================*/
58+ return strncpy (lpath, sp, llen-1);
59+}
60+
61+/*******************************************************************************
62+ * check directory path *******************************************************/
63+int chkdir (const char *path, mode_t mode)
64+{
65+ mode_t nomod;
66+ struct stat dstat;
67+ nomod = (~ mode) & 0777;
68+ /*=Check Parent directory===================================================*/
69+ errno = 0;
70+ if (stat (path, &dstat)<0) { /* no path process ****************************/
71+ switch (errno) {
72+ case EACCES: case EFAULT: case ELOOP: case ENAMETOOLONG: case ENOMEM: case ENOTDIR:
73+ return -1; break;
74+ }
75+ return 0;
76+ }
77+ else if (!S_ISDIR(dstat.st_mode)) {return -1;} /* Directory check ****/
78+ else if ((dstat.st_mode&nomod)) {return -1;} /* permission check ***/
79+
80+ return 1;
81+}
82+
83+/*******************************************************************************
84+ * Create directory ***********************************************************/
85+int mkdirs (const char *path, mode_t mode)
86+{
87+ struct stat dstat;
88+ char updir[MAXPATHLEN], *pupd;
89+ const char *ppath;
90+ /*=Init=====================================================================*/
91+ (void) memset ((char *)&dstat, 0, sizeof (struct stat));
92+ (void) memset ((char *)updir , 0, sizeof (updir ));
93+ /*=Get Parent directory=====================================================*/
94+ for (pupd=updir, ppath=path; *ppath!=0; pupd++, ppath++) {*pupd = *ppath;}
95+ rmPathLastBlock (updir);
96+
97+ /*=Check Parent directory===================================================*/
98+ if (stat (updir, &dstat)<0) { /* no path process ****************************/
99+ switch (errno) {
100+ case EACCES: case EFAULT: case ELOOP: case ENAMETOOLONG: case ENOMEM: case ENOTDIR:
101+ return 0; break;
102+ }
103+ return mkdirs (updir, mode);
104+ }
105+ /*=Mkdir====================================================================*/
106+ errno = 0;
107+ if (mkdir (path, mode)<0) {
108+ switch (errno) {
109+ case EACCES: case EFAULT: case ELOOP: case ENAMETOOLONG: case ENOMEM: case ENOSPC: case ENOTDIR: case EPERM: case EROFS:
110+ return -1; break;
111+ }
112+ }
113+
114+ return 1;
115+}
116+
117+/*******************************************************************************
118+ * remove Last Block***********************************************************/
119+ssize_t rmPathLastBlock (char *dpath)
120+{
121+ char *sp, *fp, *tp;
122+
123+ rmPathLastSlash (dpath);
124+ /*=Search===================================================================*/
125+ sp = tp = dpath;
126+ for (fp=strstr (tp, "/"); fp!=NULL; fp=strstr (tp, "/")) {
127+ if (tp==fp ) {tp = fp + 1; sp = tp;}
128+ else if (*(fp-1)=='\\') {tp = fp + 1;}
129+ else {tp = fp + 1; sp = tp;}
130+ }
131+ /*=Copy=====================================================================*/
132+ *sp = 0;
133+ if (strcpy (dpath, "/")!=0) {rmPathLastSlash (dpath);}
134+ return strlen (dpath);
135+}
136+
137+/*******************************************************************************
138+ * Remove Path Last slash *****************************************************/
139+ssize_t rmPathLastSlash (char *dpath)
140+{
141+ int len, i;
142+ packPathDupSlash (dpath);
143+ /*=Remove Last '/'==========================================================*/
144+ len = strlen (dpath);
145+ if (len==0) {return -1;}
146+ for (i=len-1; 0<=i; i--) {
147+ if (i!=0) {
148+ if (*(dpath+i)!='/') {break;}
149+ else if (0<i && *(dpath+i-1)=='\\') {break;}
150+ else {*(dpath+i) = 0x00;}
151+ }
152+ }
153+
154+ return strlen (dpath);
155+}
156+
157+/*******************************************************************************
158+ * Pack Duplicate Slash *******************************************************/
159+ssize_t packPathDupSlash (char *dpath)
160+{
161+ char *pntA, *pntB;
162+ int find, skip;
163+ for (pntA=pntB=dpath,find=skip=0;;) {
164+ if (skip==1 ) {skip = 0;}
165+ else if (*pntB=='\\' ) {skip = 1; find = 0;}
166+ else if (*pntB=='/' && find==0) {find = 1;}
167+ else if (*pntB=='/' && find==1) {pntB++; continue;}
168+ else {skip = find = 0;}
169+ if ((*pntA++ = *pntB++)==0) {break;}
170+ }
171+ return strlen (dpath);
172+}
--- release/bmpStation-0.1/lib/log.c (nonexistent)
+++ release/bmpStation-0.1/lib/log.c (revision 6)
@@ -0,0 +1,204 @@
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(SELFLIB_H__)
29+# include <selfLib.h>
30+#endif
31+#if !defined(_SYS_PARAM_H) && !defined(_SYS_PARAM_H_)
32+# include <sys/param.h>
33+#endif
34+#if !defined(_ARPA_INET_H) && !defined(_ARPA_INET_H_)
35+# include <arpa/inet.h>
36+#endif
37+#if !defined(_NETINET_IN_H) && !defined(_NETINET_IN_H_)
38+# include <netinet/in.h>
39+#endif
40+#if !defined(_SYS_SOCKET_H) && !defined(_SYS_SOCKET_H_)
41+# include <sys/socket.h>
42+#endif
43+#if !defined(_STDIO_H) && !defined(_STDIO_H_)
44+# include <stdio.h>
45+#endif
46+#if !defined(_STDARG_H) && !defined(_STDARG_H_)
47+# include <stdarg.h>
48+#endif
49+#if !defined(_STRING_H) && !defined(_STRING_H_)
50+# include <string.h>
51+#endif
52+#if !defined(_STDLIB_H_) && !defined(_STDLIB_H)
53+# include <stdlib.h>
54+#endif
55+#if !defined(_UNISTD_H) && !defined(_UNISTD_H_)
56+# include <unistd.h>
57+#endif
58+#if !defined(_TIME_H) && !defined(_TIME_H_)
59+# include <time.h>
60+#endif
61+#if !defined(_SYS_TYPES_H_) && !defined(_SYS_TYPES_H)
62+# include <sys/types.h>
63+#endif
64+#if !defined(_SYS_STAT_H_) && !defined(_SYS_STAT_H)
65+# include <sys/stat.h>
66+#endif
67+
68+
69+/*******************************************************************************
70+ * define *********************************************************************/
71+#define _YLOGMAXDATE 30
72+#define _YLOGMAXIP 64
73+#define _YLOGMAXLOG 512
74+
75+
76+/*******************************************************************************
77+ * socket *********************************************************************/
78+static void netWriteLog (FILE *w, const char *d, const char *p, const char *r, const char *s)
79+{
80+ fprintf (w, "%s %s: Peer %s: %s\n", d, p, r, s);
81+}
82+
83+/*******************************************************************************
84+ * no socket ******************************************************************/
85+static void nonetWriteLog (FILE *w, const char *d, const char *p, const char *r, const char *s)
86+{
87+ fprintf (w, "%s %s: %s\n", d, p, s);
88+}
89+
90+/*******************************************************************************
91+ * Date for log ***************************************************************/
92+int dateLog (char *date, const int size)
93+{
94+ time_t tv;
95+ struct tm *tvt;
96+ tv = time (NULL);
97+ tvt = localtime (&tv);
98+ (void) memset (date, 0, size);
99+ strftime (date, size-1, "%Y/%m/%d %H:%M:%S(%Z)", tvt);
100+
101+ return 1;
102+}
103+
104+/*******************************************************************************
105+ * Process ********************************************************************/
106+static int processLog (const char *pgn, char *pstr, const int size)
107+{
108+ (void) memset (pstr, 0, size);
109+ snprintf (pstr, size, "%s(%d)", pgn, (int)getpid ());
110+
111+ return 1;
112+}
113+
114+/*******************************************************************************
115+ * Remote *********************************************************************/
116+static int remoteLog (const int soc, char *pstr, const int size)
117+{
118+ struct sockaddr_storage peerAddr;
119+ socklen_t namelen;
120+ struct sockaddr_in *ppF;
121+ struct sockaddr_in6 *ppS;
122+ int port;
123+ char strRemote[_YLOGMAXIP];
124+ (void) memset (strRemote, 0, sizeof (strRemote));
125+ (void) memset (pstr , 0, size);
126+ (void) memset (&peerAddr, 0, sizeof (struct sockaddr_storage));
127+ /*=Get IP address ==========================================================*/
128+ namelen = sizeof (struct sockaddr_storage);
129+ if (getpeername (soc, (struct sockaddr *)&peerAddr, &namelen)<0) {return 0;}
130+ if (peerAddr.ss_family == AF_INET) {
131+ ppF = (struct sockaddr_in *)&peerAddr;
132+ port = ntohs (ppF->sin_port);
133+ inet_ntop (AF_INET, &ppF->sin_addr, strRemote, sizeof (strRemote));
134+ }
135+ else if (peerAddr.ss_family == AF_INET6) {
136+ ppS = (struct sockaddr_in6 *)&peerAddr;
137+ port = ntohs (ppS->sin6_port);
138+ inet_ntop (AF_INET6, &ppS->sin6_addr, strRemote, sizeof (strRemote));
139+ }
140+ else {return 0;}
141+ snprintf (pstr, size, "%s(%d)", strRemote, port);
142+
143+ return 1;
144+}
145+
146+/*******************************************************************************
147+ * write syslog ***************************************************************/
148+void writeLog (const char *path, const char *prog, const int fd, const char *fmt, ...)
149+{
150+ FILE *wfd;
151+ char strdate[_YLOGMAXDATE];
152+ char strPrs[MAXPATHLEN];
153+ char strRemote[NI_MAXHOST];
154+ char *jmp, *ser;
155+ char *strLog;
156+ va_list ap;
157+ void (*wfunc) (FILE *, const char*, const char*, const char*, const char*);
158+ mode_t mode;
159+
160+ if (fd<0) {wfunc = nonetWriteLog;}
161+ else {wfunc = netWriteLog;}
162+ /*=Get Infomation===========================================================*/
163+ if (!processLog (prog, strPrs , sizeof (strPrs ))) {goto end_proc;}
164+ else if (!dateLog (strdate , sizeof (strdate ))) {goto end_proc;}
165+ else if (fd<0) {}
166+ else if (!remoteLog (fd , strRemote, sizeof (strRemote))) {goto end_proc;}
167+ /*=Get Log==================================================================*/
168+ va_start(ap, fmt);
169+ if ((strLog=(char *)malloc (_YLOGMAXLOG))==NULL) {goto fin_va;}
170+ else if (vsnprintf (strLog, _YLOGMAXLOG, fmt, ap)<0 ) {goto free_data;}
171+ va_end(ap);
172+ /*=Open File================================================================*/
173+ mode = umask (022);
174+ if (strcmp (path, "stdout")==0) {wfd = stdout;}
175+ else if (strcmp (path, "stderr")==0) {wfd = stderr;}
176+ else if ((wfd=fopen (path, "a"))==NULL) {goto free_data2;}
177+
178+ /*=write Log================================================================*/
179+ ser = strLog;
180+ for (jmp=strstr (ser, "\n"); ; jmp=strstr (ser, "\n")) {
181+ if (jmp==NULL ) {}
182+ else if (*jmp=='\n') {*jmp = 0x00;}
183+ wfunc (wfd, strdate, strPrs, strRemote, ser);
184+ if (jmp==NULL) {break;}
185+ ser = jmp + 1;
186+ }
187+
188+ if (strcmp (path, "stdout")==0) {}
189+ else if (strcmp (path, "stderr")==0) {}
190+ else {fclose (wfd);}
191+
192+ free_data2:
193+ umask (mode);
194+ free (strLog);
195+ return ;
196+
197+
198+ free_data:
199+ free (strLog);
200+ fin_va:
201+ va_end(ap);
202+ end_proc:
203+ return ;
204+}
--- release/bmpStation-0.1/lib/memory.c (nonexistent)
+++ release/bmpStation-0.1/lib/memory.c (revision 6)
@@ -0,0 +1,49 @@
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+ * include ********************************************************************/
27+#if !defined(SELFLIB_H__)
28+# include <selfLib.h>
29+#endif
30+#if !defined(_SYS_TYPES_H) && !defined(_SYS_TYPES_H_)
31+# include <sys/types.h>
32+#endif
33+#if !defined(_STRING_H) && !defined(_STRING_H_)
34+# include <string.h>
35+#endif
36+
37+/*%''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''%**
38+ *: memory allocation :**
39+ *%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,%*/
40+/*******************************************************************************
41+ * memory allocation and initialize *******************************************/
42+void *imalloc (size_t size)
43+{
44+ void *pData;
45+
46+ if ((pData = malloc (size))==NULL) {return NULL;}
47+ (void) memset (pData, 0, size);
48+ return pData;
49+}
--- release/bmpStation-0.1/AUTHORS (nonexistent)
+++ release/bmpStation-0.1/AUTHORS (revision 6)
@@ -0,0 +1 @@
1+Yuki SAKAI
--- release/bmpStation-0.1/ChangeLog (nonexistent)
+++ release/bmpStation-0.1/ChangeLog (revision 6)
@@ -0,0 +1,2 @@
1+version 0.1: 2014/10/27: 1st release
2+
--- release/bmpStation-0.1/libbmp/bmpSizeCheck.c (nonexistent)
+++ release/bmpStation-0.1/libbmp/bmpSizeCheck.c (revision 6)
@@ -0,0 +1,221 @@
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(BMP_H__)
29+# include <bmp.h>
30+#endif
31+#if !defined(BGP_H__)
32+# include <bgp.h>
33+#endif
34+#if !defined(_SYS_TYPES_H) && !defined(_SYS_TYPES_H_)
35+# include <sys/types.h>
36+#endif
37+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
38+#if !defined(_SYS_ENDIAN_H) && !defined(_SYS_ENDIAN_H_)
39+# include <sys/endian.h>
40+#endif
41+#else
42+#if !defined(_ENDIAN_H) && !defined(_ENDIAN_H_)
43+# include <endian.h>
44+#endif
45+#endif
46+
47+/*+==========================================================================+**
48+ *: check BMP messages size
49+ *: arg:
50+ *: rdata : bmp messages start point address.
51+ *: maxDataLength: stored bmp messages max data size.
52+ *: return:
53+ *: plus value : BMP messages size.
54+ *: zero : data is not enough size for bmp messages.
55+ *: minus value: error
56+ *+==========================================================================+*/
57+ssize_t bmpMessageSizeCheck (u_int8_t *rdata, const ssize_t maxDataLength)
58+{
59+ ssize_t iHeaderLen;
60+ ssize_t iMsgLen;
61+ BMPv1Header *pV1Header;
62+ BMPv3Header *pV3Header;
63+ /*==========================================================================*/
64+ if (maxDataLength<1) {return 0;}
65+ else if (*rdata == 1 || *rdata == 2) {iHeaderLen = sizeof (BMPv1Header);}
66+ else if (*rdata == 3 ) {iHeaderLen = sizeof (BMPv3Header);}
67+ else {return -1;}
68+ /*==========================================================================*/
69+ if (maxDataLength<iHeaderLen) {return 0;}
70+ else if (*rdata == 3) {
71+ pV3Header = (BMPv3Header *)rdata;
72+ iMsgLen = be16toh (pV3Header->msgLen);
73+ }
74+ else {
75+ pV1Header = (BMPv1Header *)rdata;
76+ switch (pV1Header->msgType) {
77+ case BMP_MSGTYPE_ROUTEMON:
78+ iMsgLen = bmpRouteMonSize ((u_int8_t *)(pV1Header+1), maxDataLength - iHeaderLen);
79+ break;
80+ case BMP_MSGTYPE_STATISTICS:
81+ iMsgLen = bmpStatisticsSize ((u_int8_t *)(pV1Header+1), maxDataLength - iHeaderLen);
82+ break;
83+ case BMP_MSGTYPE_PEERDOWN:
84+ iMsgLen = bmpPeerDownSize ((u_int8_t *)(pV1Header+1), maxDataLength - iHeaderLen);
85+ break;
86+ case BMP_MSGTYPE_PEERUP:
87+ iMsgLen = bmpPeerUpSize ((u_int8_t *)(pV1Header+1), maxDataLength - iHeaderLen, pV1Header->version);
88+ break;
89+ default: return -1;
90+ }
91+ if (iMsgLen==0) {return 0;}
92+ else if (iMsgLen <0) {return -1;}
93+ iMsgLen += sizeof (BMPv1Header);
94+ }
95+ /*==========================================================================*/
96+ if (maxDataLength<iMsgLen) {return 0;}
97+ return iMsgLen;
98+}
99+
100+/*+==========================================================================+**
101+ *: check BMP PeerDown messages size
102+ *: arg:
103+ *: rdata : bmp peer down messages start point address.
104+ *: maxDataLength: stored messages max data size.
105+ *: return:
106+ *: plus value : BMP peer down messages size.
107+ *: zero : data is not enough size for bmp messages.
108+ *: minus value: error
109+ *+==========================================================================+*/
110+ssize_t bmpPeerDownSize (u_int8_t *rdata, const ssize_t maxDataLength)
111+{
112+ int iSize;
113+ BMPMsgPeerDown *pBMPPeerDownHeader;
114+ BGPCommonHeader *pBGPHeader;
115+ iSize = sizeof (BMPMsgPeerDown);
116+ /*==========================================================================*/
117+ if (maxDataLength<iSize) {return 0;}
118+ pBMPPeerDownHeader = (BMPMsgPeerDown *)rdata;
119+ if (pBMPPeerDownHeader->reason==BMP_PEER_DOWN_REMOTE_NO_NOTIFICATION) {return iSize;}
120+ else if (pBMPPeerDownHeader->reason==BMP_PEER_DOWN_LOCAL_NOTIFICATION ) {}
121+ else if (pBMPPeerDownHeader->reason==BMP_PEER_DOWN_LOCAL_NO_NOTIFICATION ) {}
122+ else if (pBMPPeerDownHeader->reason==BMP_PEER_DOWN_REMOTE_NOTIFICATION ) {}
123+ else {return -1;}
124+ /*==========================================================================*/
125+ pBGPHeader = (BGPCommonHeader *)(pBMPPeerDownHeader+1);
126+ if (maxDataLength<(iSize+sizeof (BGPCommonHeader))) {return 0;}
127+ iSize += be16toh (pBGPHeader->length);
128+ if (maxDataLength<iSize) {return 0;}
129+ return iSize;
130+}
131+
132+/*+==========================================================================+**
133+ *: check BMP Peer Up messages size
134+ *: arg:
135+ *: rdata : bmp peer up messages start point address.
136+ *: maxDataLength: stored messages max data size.
137+ *: return:
138+ *: plus value : BMP peer up messages size.
139+ *: zero : data is not enough size for bmp messages.
140+ *: minus value: error
141+ *+==========================================================================+*/
142+ssize_t bmpPeerUpSize (u_int8_t *rdata, const ssize_t maxDataLength, const u_int8_t ver)
143+{
144+ int iSize;
145+ BGPCommonHeader *pBGPHeader;
146+ if (ver==2) {}
147+ else if (ver==3) {}
148+ else {return -1;}
149+ /*==========================================================================*/
150+ if (ver==2) {
151+ pBGPHeader = (BGPCommonHeader *)rdata;
152+ if (maxDataLength<sizeof (BGPCommonHeader)) {return 0;}
153+ iSize = be16toh (pBGPHeader->length);
154+ }
155+ else if (ver==3) {
156+ /* unknown */
157+ iSize = maxDataLength;
158+ }
159+ if (maxDataLength<iSize) {return 0;}
160+ return iSize;
161+}
162+
163+/*+==========================================================================+**
164+ *: check BMP Statistics messages size
165+ *: arg:
166+ *: rdata : bmp statistics messages start point address.
167+ *: maxDataLength: stored messages max data size.
168+ *: return:
169+ *: plus value : BMP statistics messages size.
170+ *: zero : data is not enough size for bmp messages.
171+ *: minus value: error
172+ *+==========================================================================+*/
173+ssize_t bmpStatisticsSize (u_int8_t *rdata, const ssize_t maxDataLength)
174+{
175+ int i;
176+ int iSize, iNum;;
177+ u_int8_t *pTmp;
178+ BMPMsgStatsNum *pStatsNum;
179+ BMPMsgStatsHeader *pStatsHeader;
180+
181+ iSize = sizeof (BMPMsgStatsNum);
182+ /*==========================================================================*/
183+ if (maxDataLength<iSize) {return 0;}
184+ pStatsNum = (BMPMsgStatsNum *)rdata;
185+ iNum = be32toh (*pStatsNum);
186+ for (i=0; i<iNum; i++) {
187+ pTmp = rdata + iSize;
188+ pStatsHeader = (BMPMsgStatsHeader *)pTmp;
189+ /*========================================================================*/
190+ iSize += sizeof (BMPMsgStatsHeader);
191+ if (maxDataLength<iSize) {return 0;}
192+ /*========================================================================*/
193+ iSize += be16toh (pStatsHeader->statLen);
194+ if (maxDataLength<iSize) {return 0;}
195+ }
196+ return iSize;
197+}
198+
199+/*+==========================================================================+**
200+ *: check BMP route monitoring messages size
201+ *: arg:
202+ *: rdata : bmp route monitoring messages start point address.
203+ *: maxDataLength: stored messages max data size.
204+ *: return:
205+ *: plus value : BMP route monitoring messages size.
206+ *: zero : data is not enough size for bmp messages.
207+ *: minus value: error
208+ *+==========================================================================+*/
209+ssize_t bmpRouteMonSize (u_int8_t *rdata, const ssize_t maxDataLength)
210+{
211+ int iSize;
212+ BGPCommonHeader *pBGPHeader;
213+
214+ iSize = sizeof (BGPCommonHeader);
215+ /*==========================================================================*/
216+ if (maxDataLength<iSize) {return 0;}
217+ pBGPHeader = (BGPCommonHeader *)rdata;
218+ iSize = be16toh(pBGPHeader->length);
219+ if (maxDataLength<iSize) {return 0;}
220+ return iSize;
221+}
--- release/bmpStation-0.1/libbmp/Makefile.am (nonexistent)
+++ release/bmpStation-0.1/libbmp/Makefile.am (revision 6)
@@ -0,0 +1,11 @@
1+noinst_LIBRARIES = libbmp.a
2+include_HEADERS = bmp.h
3+libbmp_a_SOURCES = bmp.h bmpSizeCheck.c bmpDataCheck.c
4+libbmp_a_SOURCES +=
5+libbmp_a_SOURCES +=
6+libbmp_a_SOURCES +=
7+libbmp_a_SOURCES +=
8+libbmp_a_CFLAGS = -Wall -O2
9+libbmp_a_CFLAGS += -I./ -I../libbgp
10+libbmp_a_CFLAGS +=
11+libbmp_a_CFLAGS +=
--- release/bmpStation-0.1/libbmp/bmpDataGet.c (nonexistent)
+++ release/bmpStation-0.1/libbmp/bmpDataGet.c (revision 6)
@@ -0,0 +1,56 @@
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(BMP_H__)
29+# include <bmp.h>
30+#endif
31+#if !defined(BGP_H__)
32+# include <bgp.h>
33+#endif
34+#if !defined(_SYS_TYPES_H) && !defined(_SYS_TYPES_H_)
35+# include <sys/types.h>
36+#endif
37+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
38+#if !defined(_SYS_ENDIAN_H) && !defined(_SYS_ENDIAN_H_)
39+# include <sys/endian.h>
40+#endif
41+#else
42+#if !defined(_ENDIAN_H) && !defined(_ENDIAN_H_)
43+# include <endian.h>
44+#endif
45+#endif
46+
47+/*+==========================================================================+**
48+ *: check BMP messages size
49+ *: arg:
50+ *: rdata : bmp messages start point address.
51+ *: maxDataLength: stored bmp messages max data size.
52+ *: return:
53+ *: plus value : BMP messages size.
54+ *: zero : data is not enough size for bmp messages.
55+ *: minus value: error
56+ *+==========================================================================+*/
--- release/bmpStation-0.1/libbmp/bmp.h (nonexistent)
+++ release/bmpStation-0.1/libbmp/bmp.h (revision 6)
@@ -0,0 +1,341 @@
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+#if !defined(BMP_H__)
26+#define BMP_H__ 1
27+
28+/*******************************************************************************
29+ * include ********************************************************************/
30+#if !defined(_SYS_TYPES_H) && !defined(_SYS_TYPES_H_)
31+# include <sys/types.h>
32+#endif
33+#if !defined(_SYS_TIME_H) && !defined(_SYS_TIME_H_)
34+# include <sys/time.h>
35+#endif
36+
37+/*******************************************************************************
38+ * Define *********************************************************************/
39+/*=Parameter==================================================================*/
40+#define LIBBMP_MAXHEADERLEN 100 /* 2 * (Header(6B)+PerPeerHeader(42B)+Buffer(2B)) */
41+/*+==========================================================================+**
42+ *| BMP Messeages Info |**
43+ *+==========================================================================+*/
44+#define BMP_VERSION_V1 1
45+#define BMP_VERSION_V2 2
46+#define BMP_VERSION_V3 3
47+/*=Messages type==============================================================*/
48+#define BMP_MSGTYPE_ROUTEMON 0
49+#define BMP_MSGTYPE_STATISTICS 1
50+#define BMP_MSGTYPE_PEERDOWN 2
51+#define BMP_MSGTYPE_PEERUP 3
52+#define BMP_MSGTYPE_INIT 4
53+#define BMP_MSGTYPE_TERMINATE 5
54+/*=Peer Type==================================================================*/
55+#define BMP_PEERTYPE_GLOBAL 0
56+#define BMP_PEERTYPE_L3VPN 1
57+/*=Peer Flags=================================================================*/
58+#define BMP_PEERFLG_VFLG_GET 0x80
59+#define BMP_PEERFLG_VFLG_IPv6 0x80
60+#define BMP_PEERFLG_VFLG_IPv4 0x00
61+#define BMP_PEERFLG_LFLG_GET 0x40
62+/* old */
63+#define BMPPEERFLG_VFLG_GET 0x80
64+#define BMPPEERFLG_LFLG_GET 0x40
65+/*=Initiation=================================================================*/
66+#define BMP_INITMSG_STRING 0
67+#define BMP_INITMSG_SYSDESCR 1
68+#define BMP_INITMSG_SYSNAME 2
69+/* old */
70+#define BMPINITMSG_STRING 0
71+#define BMPINITMSG_SYSDESCR 1
72+#define BMPINITMSG_SYSNAME 2
73+/*=Termination================================================================*/
74+#define BMP_TERMMSG_STRING 0
75+#define BMP_TERMMSG_REASON 1
76+#define BMP_TERM_REASON_ADMIN_CLOSE 0
77+#define BMP_TERM_REASON_UNSPECIFIED 1
78+#define BMP_TERM_REASON_OUT_OF_RESOURCE 2
79+#define BMP_TERM_REASON_REDUNDANT 3
80+/* old */
81+#define BMPTERMMSG_STRING 0
82+#define BMPTERMMSG_REASON 1
83+/*=Statistics=================================================================*/
84+#define BMP_STATS_TYPE_REJECT_BY_INBOUND_POLICY 0x00 /* Number of prefixes rejected by inbound policy. */
85+#define BMP_STATS_TYPE_DUPLICATE_ADVERTISEMENTS 0x01 /* Number of (known) duplicate prefix. */
86+#define BMP_STATS_TYPE_DUPLICATE_WITHDRAWS 0x02 /* Number of (known) duplicate withdraws. */
87+#define BMP_STATS_TYPE_UPDATES_INVALIDATED_CLUSTER 0x03 /* Number of updates invalidated due to CLUSTER_LIST loop. */
88+#define BMP_STATS_TYPE_UPDATES_INVALIDATED_AS_PATH 0x04 /* Number of updates invalidated due to AS_PATH loop. */
89+#define BMP_STATS_TYPE_UPDATES_INVALIDATED_ORIGIN 0x05 /* Number of updates invalidated due to ORIGINATOR_ID. */
90+#define BMP_STATS_TYPE_UPDATES_INVALIDATED_AS_CONF 0x06 /* Number of updates invalidated due to AS_CONFED loop. */
91+#define BMP_STATS_TYPE_ROUTES_ADJ_RIBs_IN 0x07 /* Number of routes in Adj-RIBs-In. */
92+#define BMP_STATS_TYPE_ROUTES_LOC_RIB 0x08 /* Number of routes in Loc-RIB. */
93+/* old */
94+#define BMPSTATSTYPE_REJECT_BY_INBOUND_POLICY 0x00 /* Number of prefixes rejected by inbound policy. */
95+#define BMPSTATSTYPE_DUPLICATE_ADVERTISEMENTS 0x01 /* Number of (known) duplicate prefix. */
96+#define BMPSTATSTYPE_DUPLICATE_WITHDRAWS 0x02 /* Number of (known) duplicate withdraws. */
97+#define BMPSTATSTYPE_UPDATES_INVALIDATED_CLUSTER 0x03 /* Number of updates invalidated due to CLUSTER_LIST loop. */
98+#define BMPSTATSTYPE_UPDATES_INVALIDATED_AS_PATH 0x04 /* Number of updates invalidated due to AS_PATH loop. */
99+#define BMPSTATSTYPE_UPDATES_INVALIDATED_ORIGIN 0x05 /* Number of updates invalidated due to ORIGINATOR_ID. */
100+#define BMPSTATSTYPE_UPDATES_INVALIDATED_AS_CONF 0x06 /* Number of updates invalidated due to AS_CONFED loop. */
101+#define BMPSTATSTYPE_ROUTES_ADJ_RIBs_IN 0x07 /* Number of routes in Adj-RIBs-In. */
102+#define BMPSTATSTYPE_ROUTES_LOC_RIB 0x08 /* Number of routes in Loc-RIB. */
103+/*=Peer Down==================================================================*/
104+#define BMP_PEER_DOWN_LOCAL_NOTIFICATION 1
105+#define BMP_PEER_DOWN_LOCAL_NO_NOTIFICATION 2
106+#define BMP_PEER_DOWN_REMOTE_NOTIFICATION 3
107+#define BMP_PEER_DOWN_REMOTE_NO_NOTIFICATION 4
108+/* old */
109+#define BMPPEERDOWN_LOCALCLOSE 1
110+#define BMPPEERDOWN_
111+
112+
113+
114+/*******************************************************************************
115+ * Macro **********************************************************************/
116+
117+/*******************************************************************************
118+ * structure & typedef ********************************************************/
119+/*+==========================================================================+**
120+ *| BMP Messages Header |**
121+ *+==========================================================================+*/
122+/* Version: 1,2 (Header)
123+ * 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
124+ * 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
125+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
126+ * | Version | msg type | peer type | peer flags |
127+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
128+ * | Peer Distinguisher (8 Byte) |
129+ * | |
130+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
131+ * | Peer Address (16 Byte) |
132+ * | |
133+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
134+ * | Peer AS |
135+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
136+ * | Peer BGP ID |
137+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
138+ * | Timestamp (seconds) |
139+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
140+ * | Timestamp (microseconds) |
141+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
142+ * | messages(variables: Routemon, statistics, peer down, peer up) |
143+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
144+ ******************************************************************************/
145+typedef struct {
146+ u_int8_t version;
147+ u_int8_t msgType;
148+ u_int8_t peerType;
149+ u_int8_t peerFlags;
150+ u_int32_t peerDist[2];
151+ u_int32_t peerAddr[4];
152+ u_int32_t peerAS;
153+ u_int32_t peerBgpID;
154+ /* which user "struct timeval"? "u_int32_t"? */
155+ u_int32_t tv_sec;
156+ u_int32_t tv_usec;
157+} __attribute__((__packed__)) BMPv1Header;
158+#define BMPV1MSGTYPE_ROUTEMON 0
159+#define BMPV1MSGTYPE_STATISTICS 1
160+#define BMPV1MSGTYPE_PEERDOWN 2
161+#define BMPV1MSGTYPE_PEERUP 3
162+#define BMPV1PEERTYPE_GLOBAL 0
163+#define BMPV1PEERTYPE_L3VPN 1
164+#define BMPV1PEERFLG_VFLG_IPv6 0x80
165+#define BMPV1PEERFLG_VFLG_IPv4 0x00
166+
167+/* Version: 3 (Header)
168+ * 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
169+ * 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
170+ * +-+-+-+-+-+-+-+-+
171+ * | Version |
172+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
173+ * | msg length |
174+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
175+ * | msg type |
176+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
177+ * | Initiation, Termination, PerPeerHeader(variables) |
178+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
179+ ******************************************************************************/
180+/* Version: 3 */
181+typedef struct {
182+ u_int8_t version;
183+ u_int32_t msgLen;
184+ u_int8_t msgType;
185+} __attribute__((__packed__)) BMPv3Header;
186+#define BMPV3MSGTYPE_ROUTEMON 0
187+#define BMPV3MSGTYPE_STATISTICS 1
188+#define BMPV3MSGTYPE_PEERDOWN 2
189+#define BMPV3MSGTYPE_PEERUP 3
190+#define BMPV3MSGTYPE_INIT 4
191+#define BMPV3MSGTYPE_TERMINATE 5
192+
193+/* Version: 3 (Per Peer Header)
194+ * 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
195+ * 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
196+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
197+ * | peer type | peer flags |
198+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
199+ * | Peer Distinguisher (8 Byte) |
200+ * | |
201+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
202+ * | Peer Address (16 Byte) |
203+ * | |
204+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
205+ * | Peer AS |
206+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
207+ * | Peer BGP ID |
208+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
209+ * | Timestamp (seconds) |
210+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
211+ * | Timestamp (microseconds) |
212+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
213+ * | messages(variables: Routemon, statistics, peer down, peer up) |
214+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
215+ ******************************************************************************/
216+typedef struct {
217+ u_int8_t peerType;
218+ u_int8_t peerFlags;
219+ u_int32_t peerDist[2];
220+ u_int32_t peerAddr[4];
221+ u_int32_t peerAS;
222+ u_int32_t peerBgpID;
223+ /* which user "struct timeval"? "u_int32_t"? */
224+ u_int32_t tv_sec;
225+ u_int32_t tv_usec;
226+} __attribute__((__packed__)) BMPv3PerPeerHeader;
227+#define BMPV3PEERTYPE_GLOBAL 0
228+#define BMPV3PEERTYPE_L3VPN 1
229+#define BMPV3PEERFLG_VFLG_IPv6 0x80
230+#define BMPV3PEERFLG_VFLG_IPv4 0x00
231+
232+
233+/*+==========================================================================+**
234+ *| BMP Messages |**
235+ *+==========================================================================+*/
236+/*=Initiation Message=========================================================**
237+ * 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
238+ * 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
239+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
240+ * | Information type | Information length |
241+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
242+ * | Information (variables) |
243+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
244+ ******************************************************************************/
245+typedef struct {
246+ u_int16_t infoType;
247+ u_int16_t infoLen;
248+} __attribute__((__packed__)) BMPMsgInit;
249+
250+/*=Termination Message========================================================**
251+ * 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
252+ * 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
253+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
254+ * | Information type | Information length |
255+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
256+ * | Information (variables) |
257+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
258+ ******************************************************************************/
259+typedef struct {
260+ u_int16_t infoType;
261+ u_int16_t infoLen;
262+} __attribute__((__packed__)) BMPMsgTerminate;
263+
264+/*=Statistics Reports=========================================================**
265+ * 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
266+ * 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
267+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
268+ * | number of Statistics item |
269+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
270+ * | statistics messages(variables) |
271+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
272+ *
273+ * 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
274+ * 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
275+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
276+ * | Statistics type | Statistics length |
277+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
278+ * | statistics data(variables) |
279+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
280+ ******************************************************************************/
281+typedef u_int32_t BMPMsgStatsNum;
282+typedef struct {
283+ u_int16_t statType;
284+ u_int16_t statLen;
285+} __attribute__((__packed__)) BMPMsgStatsHeader;
286+typedef union {
287+ u_int32_t count32;
288+ u_int64_t count64;
289+} BMPMsgStatsData;
290+
291+/*=Peer Down Notification=====================================================**
292+ * 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
293+ * 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
294+ * +-+-+-+-+-+-+-+-+
295+ * | reason |
296+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
297+ * | statistics messages(variables) |
298+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
299+ ******************************************************************************/
300+typedef struct {
301+ u_int8_t reason;
302+} __attribute__((__packed__)) BMPMsgPeerDown;
303+
304+/*=Peer Up Notification=======================================================**
305+ * 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
306+ * 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
307+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
308+ * | Local Address (16 Byte) |
309+ * | |
310+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
311+ * | Local Port | Remote Port |
312+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
313+ * | Send OPEN Messages(variables) |
314+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
315+ * | Received OPEN Messages(variables) |
316+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
317+ *
318+ * version 2's peer up message is BGP Open messages
319+ ******************************************************************************/
320+typedef struct {
321+ u_int32_t localAddr[4];
322+ u_int16_t localPort;
323+ u_int16_t peerPort;
324+} __attribute__((__packed__)) BMPMsgPeerUp;
325+
326+/*******************************************************************************
327+ * functions ******************************************************************/
328+/*=bmpSizeCheck===============================================================*/
329+ssize_t bmpMessageSizeCheck (u_int8_t *, const ssize_t);
330+ssize_t bmpPeerDownSize (u_int8_t *, const ssize_t);
331+ssize_t bmpPeerUpSize (u_int8_t *, const ssize_t, const u_int8_t);
332+ssize_t bmpStatisticsSize (u_int8_t *, const ssize_t);
333+ssize_t bmpRouteMonSize (u_int8_t *, const ssize_t);
334+/*=bmpDataCheck===============================================================*/
335+int bmpMessageTypeCheck (const u_int8_t, const u_int8_t);
336+int bmpPeerTypeCheck (const u_int8_t, const u_int8_t);
337+
338+#endif
339+
340+
341+
--- release/bmpStation-0.1/libbmp/bmpDataCheck.c (nonexistent)
+++ release/bmpStation-0.1/libbmp/bmpDataCheck.c (revision 6)
@@ -0,0 +1,96 @@
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(BMP_H__)
29+# include <bmp.h>
30+#endif
31+#if !defined(_SYS_TYPES_H) && !defined(_SYS_TYPES_H_)
32+# include <sys/types.h>
33+#endif
34+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
35+#if !defined(_SYS_ENDIAN_H) && !defined(_SYS_ENDIAN_H_)
36+# include <sys/endian.h>
37+#endif
38+#else
39+#if !defined(_ENDIAN_H) && !defined(_ENDIAN_H_)
40+# include <endian.h>
41+#endif
42+#endif
43+
44+/*+==========================================================================+**
45+ *: check BMP messages type check
46+ *: arg:
47+ *: version : bmp Version
48+ *: msgType : bmp Message type code
49+ *: return:
50+ *: 1: O.K.
51+ *: 0: Bad
52+ *+==========================================================================+*/
53+int bmpMessageTypeCheck (const u_int8_t version, const u_int8_t msgType)
54+{
55+ switch (msgType) {
56+ case BMP_MSGTYPE_ROUTEMON:
57+ case BMP_MSGTYPE_STATISTICS:
58+ case BMP_MSGTYPE_PEERDOWN:
59+ return 1;
60+ break;
61+ case BMP_MSGTYPE_PEERUP:
62+ if (version==BMP_VERSION_V2 ||
63+ version==BMP_VERSION_V3) {return 1;}
64+ break;
65+ case BMP_MSGTYPE_INIT:
66+ case BMP_MSGTYPE_TERMINATE:
67+ if (version==BMP_VERSION_V3) {return 1;}
68+ break;
69+ default:
70+ break;
71+ }
72+ return 0;
73+}
74+
75+/*+==========================================================================+**
76+ *: check BMP peer type check
77+ *: arg:
78+ *: version : bmp Version
79+ *: peerType: bmp Peer type code
80+ *: return:
81+ *: 1: O.K.
82+ *: 0: Bad
83+ *+==========================================================================+*/
84+int bmpPeerTypeCheck (const u_int8_t version, const u_int8_t peerType)
85+{
86+ switch (peerType) {
87+ case BMP_PEERTYPE_GLOBAL:
88+ case BMP_PEERTYPE_L3VPN:
89+ return 1;
90+ break;
91+ default:
92+ break;
93+ }
94+ return 0;
95+}
96+
--- release/bmpStation-0.1/INSTALL (nonexistent)
+++ release/bmpStation-0.1/INSTALL (revision 6)
@@ -0,0 +1,365 @@
1+Installation Instructions
2+*************************
3+
4+Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005,
5+2006, 2007, 2008, 2009 Free Software Foundation, Inc.
6+
7+ Copying and distribution of this file, with or without modification,
8+are permitted in any medium without royalty provided the copyright
9+notice and this notice are preserved. This file is offered as-is,
10+without warranty of any kind.
11+
12+Basic Installation
13+==================
14+
15+ Briefly, the shell commands `./configure; make; make install' should
16+configure, build, and install this package. The following
17+more-detailed instructions are generic; see the `README' file for
18+instructions specific to this package. Some packages provide this
19+`INSTALL' file but do not implement all of the features documented
20+below. The lack of an optional feature in a given package is not
21+necessarily a bug. More recommendations for GNU packages can be found
22+in *note Makefile Conventions: (standards)Makefile Conventions.
23+
24+ The `configure' shell script attempts to guess correct values for
25+various system-dependent variables used during compilation. It uses
26+those values to create a `Makefile' in each directory of the package.
27+It may also create one or more `.h' files containing system-dependent
28+definitions. Finally, it creates a shell script `config.status' that
29+you can run in the future to recreate the current configuration, and a
30+file `config.log' containing compiler output (useful mainly for
31+debugging `configure').
32+
33+ It can also use an optional file (typically called `config.cache'
34+and enabled with `--cache-file=config.cache' or simply `-C') that saves
35+the results of its tests to speed up reconfiguring. Caching is
36+disabled by default to prevent problems with accidental use of stale
37+cache files.
38+
39+ If you need to do unusual things to compile the package, please try
40+to figure out how `configure' could check whether to do them, and mail
41+diffs or instructions to the address given in the `README' so they can
42+be considered for the next release. If you are using the cache, and at
43+some point `config.cache' contains results you don't want to keep, you
44+may remove or edit it.
45+
46+ The file `configure.ac' (or `configure.in') is used to create
47+`configure' by a program called `autoconf'. You need `configure.ac' if
48+you want to change it or regenerate `configure' using a newer version
49+of `autoconf'.
50+
51+ The simplest way to compile this package is:
52+
53+ 1. `cd' to the directory containing the package's source code and type
54+ `./configure' to configure the package for your system.
55+
56+ Running `configure' might take a while. While running, it prints
57+ some messages telling which features it is checking for.
58+
59+ 2. Type `make' to compile the package.
60+
61+ 3. Optionally, type `make check' to run any self-tests that come with
62+ the package, generally using the just-built uninstalled binaries.
63+
64+ 4. Type `make install' to install the programs and any data files and
65+ documentation. When installing into a prefix owned by root, it is
66+ recommended that the package be configured and built as a regular
67+ user, and only the `make install' phase executed with root
68+ privileges.
69+
70+ 5. Optionally, type `make installcheck' to repeat any self-tests, but
71+ this time using the binaries in their final installed location.
72+ This target does not install anything. Running this target as a
73+ regular user, particularly if the prior `make install' required
74+ root privileges, verifies that the installation completed
75+ correctly.
76+
77+ 6. You can remove the program binaries and object files from the
78+ source code directory by typing `make clean'. To also remove the
79+ files that `configure' created (so you can compile the package for
80+ a different kind of computer), type `make distclean'. There is
81+ also a `make maintainer-clean' target, but that is intended mainly
82+ for the package's developers. If you use it, you may have to get
83+ all sorts of other programs in order to regenerate files that came
84+ with the distribution.
85+
86+ 7. Often, you can also type `make uninstall' to remove the installed
87+ files again. In practice, not all packages have tested that
88+ uninstallation works correctly, even though it is required by the
89+ GNU Coding Standards.
90+
91+ 8. Some packages, particularly those that use Automake, provide `make
92+ distcheck', which can by used by developers to test that all other
93+ targets like `make install' and `make uninstall' work correctly.
94+ This target is generally not run by end users.
95+
96+Compilers and Options
97+=====================
98+
99+ Some systems require unusual options for compilation or linking that
100+the `configure' script does not know about. Run `./configure --help'
101+for details on some of the pertinent environment variables.
102+
103+ You can give `configure' initial values for configuration parameters
104+by setting variables in the command line or in the environment. Here
105+is an example:
106+
107+ ./configure CC=c99 CFLAGS=-g LIBS=-lposix
108+
109+ *Note Defining Variables::, for more details.
110+
111+Compiling For Multiple Architectures
112+====================================
113+
114+ You can compile the package for more than one kind of computer at the
115+same time, by placing the object files for each architecture in their
116+own directory. To do this, you can use GNU `make'. `cd' to the
117+directory where you want the object files and executables to go and run
118+the `configure' script. `configure' automatically checks for the
119+source code in the directory that `configure' is in and in `..'. This
120+is known as a "VPATH" build.
121+
122+ With a non-GNU `make', it is safer to compile the package for one
123+architecture at a time in the source code directory. After you have
124+installed the package for one architecture, use `make distclean' before
125+reconfiguring for another architecture.
126+
127+ On MacOS X 10.5 and later systems, you can create libraries and
128+executables that work on multiple system types--known as "fat" or
129+"universal" binaries--by specifying multiple `-arch' options to the
130+compiler but only a single `-arch' option to the preprocessor. Like
131+this:
132+
133+ ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
134+ CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
135+ CPP="gcc -E" CXXCPP="g++ -E"
136+
137+ This is not guaranteed to produce working output in all cases, you
138+may have to build one architecture at a time and combine the results
139+using the `lipo' tool if you have problems.
140+
141+Installation Names
142+==================
143+
144+ By default, `make install' installs the package's commands under
145+`/usr/local/bin', include files under `/usr/local/include', etc. You
146+can specify an installation prefix other than `/usr/local' by giving
147+`configure' the option `--prefix=PREFIX', where PREFIX must be an
148+absolute file name.
149+
150+ You can specify separate installation prefixes for
151+architecture-specific files and architecture-independent files. If you
152+pass the option `--exec-prefix=PREFIX' to `configure', the package uses
153+PREFIX as the prefix for installing programs and libraries.
154+Documentation and other data files still use the regular prefix.
155+
156+ In addition, if you use an unusual directory layout you can give
157+options like `--bindir=DIR' to specify different values for particular
158+kinds of files. Run `configure --help' for a list of the directories
159+you can set and what kinds of files go in them. In general, the
160+default for these options is expressed in terms of `${prefix}', so that
161+specifying just `--prefix' will affect all of the other directory
162+specifications that were not explicitly provided.
163+
164+ The most portable way to affect installation locations is to pass the
165+correct locations to `configure'; however, many packages provide one or
166+both of the following shortcuts of passing variable assignments to the
167+`make install' command line to change installation locations without
168+having to reconfigure or recompile.
169+
170+ The first method involves providing an override variable for each
171+affected directory. For example, `make install
172+prefix=/alternate/directory' will choose an alternate location for all
173+directory configuration variables that were expressed in terms of
174+`${prefix}'. Any directories that were specified during `configure',
175+but not in terms of `${prefix}', must each be overridden at install
176+time for the entire installation to be relocated. The approach of
177+makefile variable overrides for each directory variable is required by
178+the GNU Coding Standards, and ideally causes no recompilation.
179+However, some platforms have known limitations with the semantics of
180+shared libraries that end up requiring recompilation when using this
181+method, particularly noticeable in packages that use GNU Libtool.
182+
183+ The second method involves providing the `DESTDIR' variable. For
184+example, `make install DESTDIR=/alternate/directory' will prepend
185+`/alternate/directory' before all installation names. The approach of
186+`DESTDIR' overrides is not required by the GNU Coding Standards, and
187+does not work on platforms that have drive letters. On the other hand,
188+it does better at avoiding recompilation issues, and works well even
189+when some directory options were not specified in terms of `${prefix}'
190+at `configure' time.
191+
192+Optional Features
193+=================
194+
195+ If the package supports it, you can cause programs to be installed
196+with an extra prefix or suffix on their names by giving `configure' the
197+option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
198+
199+ Some packages pay attention to `--enable-FEATURE' options to
200+`configure', where FEATURE indicates an optional part of the package.
201+They may also pay attention to `--with-PACKAGE' options, where PACKAGE
202+is something like `gnu-as' or `x' (for the X Window System). The
203+`README' should mention any `--enable-' and `--with-' options that the
204+package recognizes.
205+
206+ For packages that use the X Window System, `configure' can usually
207+find the X include and library files automatically, but if it doesn't,
208+you can use the `configure' options `--x-includes=DIR' and
209+`--x-libraries=DIR' to specify their locations.
210+
211+ Some packages offer the ability to configure how verbose the
212+execution of `make' will be. For these packages, running `./configure
213+--enable-silent-rules' sets the default to minimal output, which can be
214+overridden with `make V=1'; while running `./configure
215+--disable-silent-rules' sets the default to verbose, which can be
216+overridden with `make V=0'.
217+
218+Particular systems
219+==================
220+
221+ On HP-UX, the default C compiler is not ANSI C compatible. If GNU
222+CC is not installed, it is recommended to use the following options in
223+order to use an ANSI C compiler:
224+
225+ ./configure CC="cc -Ae -D_XOPEN_SOURCE=500"
226+
227+and if that doesn't work, install pre-built binaries of GCC for HP-UX.
228+
229+ On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot
230+parse its `<wchar.h>' header file. The option `-nodtk' can be used as
231+a workaround. If GNU CC is not installed, it is therefore recommended
232+to try
233+
234+ ./configure CC="cc"
235+
236+and if that doesn't work, try
237+
238+ ./configure CC="cc -nodtk"
239+
240+ On Solaris, don't put `/usr/ucb' early in your `PATH'. This
241+directory contains several dysfunctional programs; working variants of
242+these programs are available in `/usr/bin'. So, if you need `/usr/ucb'
243+in your `PATH', put it _after_ `/usr/bin'.
244+
245+ On Haiku, software installed for all users goes in `/boot/common',
246+not `/usr/local'. It is recommended to use the following options:
247+
248+ ./configure --prefix=/boot/common
249+
250+Specifying the System Type
251+==========================
252+
253+ There may be some features `configure' cannot figure out
254+automatically, but needs to determine by the type of machine the package
255+will run on. Usually, assuming the package is built to be run on the
256+_same_ architectures, `configure' can figure that out, but if it prints
257+a message saying it cannot guess the machine type, give it the
258+`--build=TYPE' option. TYPE can either be a short name for the system
259+type, such as `sun4', or a canonical name which has the form:
260+
261+ CPU-COMPANY-SYSTEM
262+
263+where SYSTEM can have one of these forms:
264+
265+ OS
266+ KERNEL-OS
267+
268+ See the file `config.sub' for the possible values of each field. If
269+`config.sub' isn't included in this package, then this package doesn't
270+need to know the machine type.
271+
272+ If you are _building_ compiler tools for cross-compiling, you should
273+use the option `--target=TYPE' to select the type of system they will
274+produce code for.
275+
276+ If you want to _use_ a cross compiler, that generates code for a
277+platform different from the build platform, you should specify the
278+"host" platform (i.e., that on which the generated programs will
279+eventually be run) with `--host=TYPE'.
280+
281+Sharing Defaults
282+================
283+
284+ If you want to set default values for `configure' scripts to share,
285+you can create a site shell script called `config.site' that gives
286+default values for variables like `CC', `cache_file', and `prefix'.
287+`configure' looks for `PREFIX/share/config.site' if it exists, then
288+`PREFIX/etc/config.site' if it exists. Or, you can set the
289+`CONFIG_SITE' environment variable to the location of the site script.
290+A warning: not all `configure' scripts look for a site script.
291+
292+Defining Variables
293+==================
294+
295+ Variables not defined in a site shell script can be set in the
296+environment passed to `configure'. However, some packages may run
297+configure again during the build, and the customized values of these
298+variables may be lost. In order to avoid this problem, you should set
299+them in the `configure' command line, using `VAR=value'. For example:
300+
301+ ./configure CC=/usr/local2/bin/gcc
302+
303+causes the specified `gcc' to be used as the C compiler (unless it is
304+overridden in the site shell script).
305+
306+Unfortunately, this technique does not work for `CONFIG_SHELL' due to
307+an Autoconf bug. Until the bug is fixed you can use this workaround:
308+
309+ CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash
310+
311+`configure' Invocation
312+======================
313+
314+ `configure' recognizes the following options to control how it
315+operates.
316+
317+`--help'
318+`-h'
319+ Print a summary of all of the options to `configure', and exit.
320+
321+`--help=short'
322+`--help=recursive'
323+ Print a summary of the options unique to this package's
324+ `configure', and exit. The `short' variant lists options used
325+ only in the top level, while the `recursive' variant lists options
326+ also present in any nested packages.
327+
328+`--version'
329+`-V'
330+ Print the version of Autoconf used to generate the `configure'
331+ script, and exit.
332+
333+`--cache-file=FILE'
334+ Enable the cache: use and save the results of the tests in FILE,
335+ traditionally `config.cache'. FILE defaults to `/dev/null' to
336+ disable caching.
337+
338+`--config-cache'
339+`-C'
340+ Alias for `--cache-file=config.cache'.
341+
342+`--quiet'
343+`--silent'
344+`-q'
345+ Do not print messages saying which checks are being made. To
346+ suppress all normal output, redirect it to `/dev/null' (any error
347+ messages will still be shown).
348+
349+`--srcdir=DIR'
350+ Look for the package's source code in directory DIR. Usually
351+ `configure' can determine that directory automatically.
352+
353+`--prefix=DIR'
354+ Use DIR as the installation prefix. *note Installation Names::
355+ for more details, including other options available for fine-tuning
356+ the installation locations.
357+
358+`--no-create'
359+`-n'
360+ Run the configure checks, but stop before creating any output
361+ files.
362+
363+`configure' also accepts some other, not widely useful, options. Run
364+`configure --help' for more details.
365+
--- release/bmpStation-0.1/COPYING (nonexistent)
+++ release/bmpStation-0.1/COPYING (revision 6)
@@ -0,0 +1,21 @@
1+The MIT License (MIT)
2+
3+Copyright (c) 2014 Yuki SAKAI
4+
5+Permission is hereby granted, free of charge, to any person obtaining a copy
6+of this software and associated documentation files (the "Software"), to deal
7+in the Software without restriction, including without limitation the rights
8+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+copies of the Software, and to permit persons to whom the Software is
10+furnished to do so, subject to the following conditions:
11+
12+The above copyright notice and this permission notice shall be included in
13+all copies or substantial portions of the Software.
14+
15+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+THE SOFTWARE.