Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,138 +0,0 @@
1
-/*
2
- * Copyright (C) 2010 iptelorg GmbH
3
- *
4
- * Permission to use, copy, modify, and distribute this software for any
5
- * purpose with or without fee is hereby granted, provided that the above
6
- * copyright notice and this permission notice appear in all copies.
7
- *
8
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
- */
16
-
17
-/** Kamailio core :: raw socket udp listen functions.
18
- *  @file raw_listener.c
19
- *  @ingroup core
20
- *  Module: @ref core
21
- */
22
-
23
-#ifdef USE_RAW_SOCKS
24
-
25
-
26
-#include "raw_listener.h"
27
-#include "raw_sock.h"
28
-#include "receive.h"
29
-
30
-#include <errno.h>
31
-#include <string.h>
32
-
33
-struct socket_info* raw_udp_sendipv4=0;
34
-
35
-/** creates a raw socket based on a socket_info structure.
36
- * Side-effects: sets raw_udp_sendipv4 if not already set.
37
- * @param si - pointer to partially filled socket_info structure (su must
38
- *              be set).
39
- * @param iface - pointer to network interface to bind on (str). Can be null.
40
- * @param iphdr_incl - 1 if send on these socket will include the IP header.
41
- * @return <0 on error, socket on success.
42
- */
43
-int raw_listener_init(struct socket_info* si, str* iface, int iphdr_incl)
44
-{
45
-	int sock;
46
-	struct ip_addr ip;
47
-	
48
-	su2ip_addr(&ip, &si->su);
49
-	sock=raw_udp4_socket(&ip, iface, iphdr_incl);
50
-	if (sock>=0){
51
-		if (raw_udp_sendipv4==0 || iface==0 || iface->s==0)
52
-			raw_udp_sendipv4=si;
53
-	}
54
-	return sock;
55
-}
56
-
57
-
58
-
59
-/** receive sip udp ipv4 packets over a raw socket in a loop.
60
- * It should be called by a "raw socket receiver" process
61
- * (since the function never exits unless it encounters a
62
- *  critical error).
63
- * @param rsock - initialized raw socket.
64
- * @param port1 - start of port range.
65
- * @param port2 - end of port range. If 0 it's equivalent to listening only
66
- *                on port1.
67
- * @return <0 on error, never returns on success.
68
- */
69
-int raw_udp4_rcv_loop(int rsock, int port1, int port2)
70
-{
71
-	static char buf[BUF_SIZE+1];
72
-	char* p;
73
-	char* tmp;
74
-	union sockaddr_union from;
75
-	union sockaddr_union to;
76
-	struct receive_info ri;
77
-	struct raw_filter rf;
78
-	int len;
79
-	
80
-	/* this will not change */
81
-	from.sin.sin_family=AF_INET;
82
-	ri.bind_address=0;
83
-	ri.proto=PROTO_UDP;
84
-	ri.proto_reserved1=0;
85
-	ri.proto_reserved2=0;
86
-	/* set filter to match any address but with the specified port range */
87
-	memset(&rf, 0, sizeof(rf));
88
-	rf.dst.ip.af=AF_INET;
89
-	rf.dst.ip.len=4;
90
-	rf.dst.mask.af=AF_INET;
91
-	rf.dst.mask.len=4;
92
-	rf.proto=PROTO_UDP;
93
-	rf.port1=port1;
94
-	rf.port2=port2?port2:port1;
95
-	for(;;){
96
-		p=buf;
97
-		len=raw_udp4_recv(rsock, &p, BUF_SIZE, &from, &to, &rf);
98
-		if (len<0){
99
-			if (len==-1){
100
-				LM_ERR("%s [%d]\n", strerror(errno), errno);
101
-				if ((errno==EINTR)||(errno==EWOULDBLOCK))
102
-					continue;
103
-				else
104
-					goto error;
105
-			}else{
106
-				LM_DBG("error len: %d\n", len);
107
-				continue;
108
-			}
109
-		}
110
-		/* we must 0-term the message */
111
-		p[len]=0;
112
-		ri.src_su=from;
113
-		su2ip_addr(&ri.src_ip, &from);
114
-		ri.src_port=su_getport(&from);
115
-		su2ip_addr(&ri.dst_ip, &to);
116
-		ri.dst_port=su_getport(&to);
117
-		/* sanity checks */
118
-		if (len<MIN_UDP_PACKET){
119
-			tmp=ip_addr2a(&ri.src_ip);
120
-			LM_DBG("probing packet received from %s %d\n",
121
-					tmp, htons(ri.src_port));
122
-			continue;
123
-		}
124
-		if (ri.src_port==0){
125
-			tmp=ip_addr2a(&ri.src_ip);
126
-			LM_INFO("dropping 0 port packet from %s\n", tmp);
127
-			continue;
128
-		}
129
-		tmp=ip_addr2a(&ri.src_ip);
130
-		LM_DBG("received from %s:\n[%.*s]\n", tmp, len, p);
131
-		receive_msg(p, len, &ri);
132
-	}
133
-error:
134
-	return -1;
135
-}
136
-
137
-
138
-#endif /* USE_RAW_SOCKS */
Browse code

raw_listener.c: logging: DBG -> LM_DBG

Ovidiu Sas authored on 13/01/2015 17:28:42
Showing 1 changed files
... ...
@@ -97,13 +97,13 @@ int raw_udp4_rcv_loop(int rsock, int port1, int port2)
97 97
 		len=raw_udp4_recv(rsock, &p, BUF_SIZE, &from, &to, &rf);
98 98
 		if (len<0){
99 99
 			if (len==-1){
100
-				LM_ERR("raw_udp4_recv: %s [%d]\n", strerror(errno), errno);
100
+				LM_ERR("%s [%d]\n", strerror(errno), errno);
101 101
 				if ((errno==EINTR)||(errno==EWOULDBLOCK))
102 102
 					continue;
103 103
 				else
104 104
 					goto error;
105 105
 			}else{
106
-				DBG("raw_udp4_rcv_loop: raw_udp4_recv error: %d\n", len);
106
+				LM_DBG("error len: %d\n", len);
107 107
 				continue;
108 108
 			}
109 109
 		}
... ...
@@ -117,7 +117,7 @@ int raw_udp4_rcv_loop(int rsock, int port1, int port2)
117 117
 		/* sanity checks */
118 118
 		if (len<MIN_UDP_PACKET){
119 119
 			tmp=ip_addr2a(&ri.src_ip);
120
-			DBG("raw_udp4_rcv_loop: probing packet received from %s %d\n",
120
+			LM_DBG("probing packet received from %s %d\n",
121 121
 					tmp, htons(ri.src_port));
122 122
 			continue;
123 123
 		}
... ...
@@ -127,7 +127,7 @@ int raw_udp4_rcv_loop(int rsock, int port1, int port2)
127 127
 			continue;
128 128
 		}
129 129
 		tmp=ip_addr2a(&ri.src_ip);
130
-		DBG("raw_udp4_rcv_loop: received from %s:\n[%.*s]\n", tmp, len, p);
130
+		LM_DBG("received from %s:\n[%.*s]\n", tmp, len, p);
131 131
 		receive_msg(p, len, &ri);
132 132
 	}
133 133
 error:
Browse code

Core Removed history, svn $id$ and doxygen udpates on the .c files

Olle E. Johansson authored on 03/01/2015 09:53:17
Showing 1 changed files
... ...
@@ -13,16 +13,12 @@
13 13
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 14
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 15
  */
16
-/** raw socket udp listen functions.
16
+
17
+/** Kamailio core :: raw socket udp listen functions.
17 18
  *  @file raw_listener.c
18 19
  *  @ingroup core
19 20
  *  Module: @ref core
20 21
  */
21
-/*
22
- * History:
23
- * --------
24
- *  2010-06-09  intial version (from older code) andrei
25
- */
26 22
 
27 23
 #ifdef USE_RAW_SOCKS
28 24
 
Browse code

raw_listener.c: logging: convert LOG to LM_*

Ovidiu Sas authored on 04/10/2014 00:50:10
Showing 1 changed files
... ...
@@ -101,8 +101,7 @@ int raw_udp4_rcv_loop(int rsock, int port1, int port2)
101 101
 		len=raw_udp4_recv(rsock, &p, BUF_SIZE, &from, &to, &rf);
102 102
 		if (len<0){
103 103
 			if (len==-1){
104
-				LOG(L_ERR, "ERROR: raw_udp4_rcv_loop:raw_udp4_recv: %s [%d]\n",
105
-						strerror(errno), errno);
104
+				LM_ERR("raw_udp4_recv: %s [%d]\n", strerror(errno), errno);
106 105
 				if ((errno==EINTR)||(errno==EWOULDBLOCK))
107 106
 					continue;
108 107
 				else
... ...
@@ -128,8 +127,7 @@ int raw_udp4_rcv_loop(int rsock, int port1, int port2)
128 127
 		}
129 128
 		if (ri.src_port==0){
130 129
 			tmp=ip_addr2a(&ri.src_ip);
131
-			LOG(L_INFO, "raw_udp4_rcv_loop: dropping 0 port packet from %s\n",
132
-						tmp);
130
+			LM_INFO("dropping 0 port packet from %s\n", tmp);
133 131
 			continue;
134 132
 		}
135 133
 		tmp=ip_addr2a(&ri.src_ip);
Browse code

raw socket: compilation fixes

Andrei Pelinescu-Onciul authored on 15/06/2010 14:24:46
Showing 1 changed files
... ...
@@ -26,18 +26,15 @@
26 26
 
27 27
 #ifdef USE_RAW_SOCKS
28 28
 
29
-#include "../../config.h"
30
-#include "../../receive.h"
31 29
 
32 30
 #include "raw_listener.h"
33 31
 #include "raw_sock.h"
34
-#include "tlb_send.h"
35
-#include "tlb_cfg.h"
32
+#include "receive.h"
36 33
 
37 34
 #include <errno.h>
38 35
 #include <string.h>
39 36
 
40
-struct raw_listen_info* raw_sendipv4=0;
37
+struct socket_info* raw_udp_sendipv4=0;
41 38
 
42 39
 /** creates a raw socket based on a socket_info structure.
43 40
  * Side-effects: sets raw_udp_sendipv4 if not already set.
... ...
@@ -55,7 +52,7 @@ int raw_listener_init(struct socket_info* si, str* iface, int iphdr_incl)
55 52
 	su2ip_addr(&ip, &si->su);
56 53
 	sock=raw_udp4_socket(&ip, iface, iphdr_incl);
57 54
 	if (sock>=0){
58
-		if (raw_sendipv4==0 || iface==0 || iface->s==0)
55
+		if (raw_udp_sendipv4==0 || iface==0 || iface->s==0)
59 56
 			raw_udp_sendipv4=si;
60 57
 	}
61 58
 	return sock;
Browse code

core: basic support for receiving udp sip packets on raw sockets

Functions for receiving udp sip packets from raw sockets.

Andrei Pelinescu-Onciul authored on 09/06/2010 20:55:21
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,147 @@
1
+/*
2
+ * Copyright (C) 2010 iptelorg GmbH
3
+ *
4
+ * Permission to use, copy, modify, and distribute this software for any
5
+ * purpose with or without fee is hereby granted, provided that the above
6
+ * copyright notice and this permission notice appear in all copies.
7
+ *
8
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
+ */
16
+/** raw socket udp listen functions.
17
+ *  @file raw_listener.c
18
+ *  @ingroup core
19
+ *  Module: @ref core
20
+ */
21
+/*
22
+ * History:
23
+ * --------
24
+ *  2010-06-09  intial version (from older code) andrei
25
+ */
26
+
27
+#ifdef USE_RAW_SOCKS
28
+
29
+#include "../../config.h"
30
+#include "../../receive.h"
31
+
32
+#include "raw_listener.h"
33
+#include "raw_sock.h"
34
+#include "tlb_send.h"
35
+#include "tlb_cfg.h"
36
+
37
+#include <errno.h>
38
+#include <string.h>
39
+
40
+struct raw_listen_info* raw_sendipv4=0;
41
+
42
+/** creates a raw socket based on a socket_info structure.
43
+ * Side-effects: sets raw_udp_sendipv4 if not already set.
44
+ * @param si - pointer to partially filled socket_info structure (su must
45
+ *              be set).
46
+ * @param iface - pointer to network interface to bind on (str). Can be null.
47
+ * @param iphdr_incl - 1 if send on these socket will include the IP header.
48
+ * @return <0 on error, socket on success.
49
+ */
50
+int raw_listener_init(struct socket_info* si, str* iface, int iphdr_incl)
51
+{
52
+	int sock;
53
+	struct ip_addr ip;
54
+	
55
+	su2ip_addr(&ip, &si->su);
56
+	sock=raw_udp4_socket(&ip, iface, iphdr_incl);
57
+	if (sock>=0){
58
+		if (raw_sendipv4==0 || iface==0 || iface->s==0)
59
+			raw_udp_sendipv4=si;
60
+	}
61
+	return sock;
62
+}
63
+
64
+
65
+
66
+/** receive sip udp ipv4 packets over a raw socket in a loop.
67
+ * It should be called by a "raw socket receiver" process
68
+ * (since the function never exits unless it encounters a
69
+ *  critical error).
70
+ * @param rsock - initialized raw socket.
71
+ * @param port1 - start of port range.
72
+ * @param port2 - end of port range. If 0 it's equivalent to listening only
73
+ *                on port1.
74
+ * @return <0 on error, never returns on success.
75
+ */
76
+int raw_udp4_rcv_loop(int rsock, int port1, int port2)
77
+{
78
+	static char buf[BUF_SIZE+1];
79
+	char* p;
80
+	char* tmp;
81
+	union sockaddr_union from;
82
+	union sockaddr_union to;
83
+	struct receive_info ri;
84
+	struct raw_filter rf;
85
+	int len;
86
+	
87
+	/* this will not change */
88
+	from.sin.sin_family=AF_INET;
89
+	ri.bind_address=0;
90
+	ri.proto=PROTO_UDP;
91
+	ri.proto_reserved1=0;
92
+	ri.proto_reserved2=0;
93
+	/* set filter to match any address but with the specified port range */
94
+	memset(&rf, 0, sizeof(rf));
95
+	rf.dst.ip.af=AF_INET;
96
+	rf.dst.ip.len=4;
97
+	rf.dst.mask.af=AF_INET;
98
+	rf.dst.mask.len=4;
99
+	rf.proto=PROTO_UDP;
100
+	rf.port1=port1;
101
+	rf.port2=port2?port2:port1;
102
+	for(;;){
103
+		p=buf;
104
+		len=raw_udp4_recv(rsock, &p, BUF_SIZE, &from, &to, &rf);
105
+		if (len<0){
106
+			if (len==-1){
107
+				LOG(L_ERR, "ERROR: raw_udp4_rcv_loop:raw_udp4_recv: %s [%d]\n",
108
+						strerror(errno), errno);
109
+				if ((errno==EINTR)||(errno==EWOULDBLOCK))
110
+					continue;
111
+				else
112
+					goto error;
113
+			}else{
114
+				DBG("raw_udp4_rcv_loop: raw_udp4_recv error: %d\n", len);
115
+				continue;
116
+			}
117
+		}
118
+		/* we must 0-term the message */
119
+		p[len]=0;
120
+		ri.src_su=from;
121
+		su2ip_addr(&ri.src_ip, &from);
122
+		ri.src_port=su_getport(&from);
123
+		su2ip_addr(&ri.dst_ip, &to);
124
+		ri.dst_port=su_getport(&to);
125
+		/* sanity checks */
126
+		if (len<MIN_UDP_PACKET){
127
+			tmp=ip_addr2a(&ri.src_ip);
128
+			DBG("raw_udp4_rcv_loop: probing packet received from %s %d\n",
129
+					tmp, htons(ri.src_port));
130
+			continue;
131
+		}
132
+		if (ri.src_port==0){
133
+			tmp=ip_addr2a(&ri.src_ip);
134
+			LOG(L_INFO, "raw_udp4_rcv_loop: dropping 0 port packet from %s\n",
135
+						tmp);
136
+			continue;
137
+		}
138
+		tmp=ip_addr2a(&ri.src_ip);
139
+		DBG("raw_udp4_rcv_loop: received from %s:\n[%.*s]\n", tmp, len, p);
140
+		receive_msg(p, len, &ri);
141
+	}
142
+error:
143
+	return -1;
144
+}
145
+
146
+
147
+#endif /* USE_RAW_SOCKS */