... | ... |
@@ -152,8 +152,7 @@ int do_action(struct action* a, struct sip_msg* msg) |
152 | 152 |
p->tx_bytes+=msg->len; |
153 | 153 |
send_sock=get_send_socket(to); |
154 | 154 |
if (send_sock!=0){ |
155 |
- ret=udp_send(send_sock, msg->orig, msg->len, to, |
|
156 |
- sizeof(union sockaddr_union)); |
|
155 |
+ ret=udp_send(send_sock, msg->orig, msg->len, to); |
|
157 | 156 |
}else{ |
158 | 157 |
ret=-1; |
159 | 158 |
} |
... | ... |
@@ -189,8 +189,7 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p) |
189 | 189 |
DBG("Sending:\n%s.\n", buf); |
190 | 190 |
DBG("orig. len=%d, new_len=%d\n", msg->len, len ); |
191 | 191 |
|
192 |
- if (udp_send(send_sock, buf, len, to, |
|
193 |
- sizeof(union sockaddr_union))==-1){ |
|
192 |
+ if (udp_send(send_sock, buf, len, to)==-1){ |
|
194 | 193 |
ser_error=E_SEND; |
195 | 194 |
p->errors++; |
196 | 195 |
p->ok=0; |
... | ... |
@@ -335,8 +334,7 @@ int forward_reply(struct sip_msg* msg) |
335 | 334 |
goto error; |
336 | 335 |
} |
337 | 336 |
|
338 |
- if (udp_send(send_sock, new_buf,new_len, to, |
|
339 |
- sizeof(union sockaddr_union))==-1) |
|
337 |
+ if (udp_send(send_sock, new_buf,new_len, to)==-1) |
|
340 | 338 |
{ |
341 | 339 |
STATS_TX_DROPS; |
342 | 340 |
goto error; |
... | ... |
@@ -54,10 +54,23 @@ struct socket_info{ |
54 | 54 |
unsigned short port_no; /* port number */ |
55 | 55 |
str port_no_str; /* port number converted to string -- optimization*/ |
56 | 56 |
int is_ip; /* 1 if name is an ip address, 0 if not -- optimization*/ |
57 |
+ union sockaddr_union su; |
|
57 | 58 |
}; |
58 | 59 |
|
59 | 60 |
|
60 |
- |
|
61 |
+/* len of the sockaddr */ |
|
62 |
+#ifdef __FreeBSD__ |
|
63 |
+#define sockaddru_len(su) ((su).s.sa_len) |
|
64 |
+#else |
|
65 |
+#ifdef USE_IPV6 |
|
66 |
+#define sockaddru_len(su) \ |
|
67 |
+ (((su).s.sa_family==AF_INET6)?sizeof(struct sockaddr_in6):\ |
|
68 |
+ sizeof(struct sockaddr_in)) |
|
69 |
+#else |
|
70 |
+#define sockaddru_len(su) sizeof(struct sockaddr_in) |
|
71 |
+#endif /*USE_IPV6*/ |
|
72 |
+#endif /*__FreeBSD__*/ |
|
73 |
+ |
|
61 | 74 |
/* inits an ip_addr with the addr. info from a hostent structure |
62 | 75 |
* ip = struct ip_addr* |
63 | 76 |
* he= struct hostent* |
... | ... |
@@ -23,8 +23,7 @@ int send_pr_buffer( struct retr_buf *rb, |
23 | 23 |
void *buf, int len, char *function, int line ) |
24 | 24 |
{ |
25 | 25 |
if (buf && len && rb ) |
26 |
- return udp_send( rb->send_sock, buf, |
|
27 |
- len, &rb->to, sizeof(union sockaddr_union) ) ; |
|
26 |
+ return udp_send( rb->send_sock, buf, len, &rb->to) ; |
|
28 | 27 |
else { |
29 | 28 |
LOG(L_CRIT, "ERROR: sending an empty buffer from %s (%d)\n", |
30 | 29 |
function, line ); |
... | ... |
@@ -113,26 +113,20 @@ int probe_max_receive_buffer( int udp_sock ) |
113 | 113 |
int udp_init(struct socket_info* sock_info) |
114 | 114 |
{ |
115 | 115 |
union sockaddr_union* addr; |
116 |
- int sock_len; |
|
117 | 116 |
int optval; |
118 | 117 |
|
119 |
- |
|
118 |
+ addr=&sock_info->su; |
|
119 |
+/* |
|
120 | 120 |
addr=(union sockaddr_union*)malloc(sizeof(union sockaddr_union)); |
121 | 121 |
if (addr==0){ |
122 | 122 |
LOG(L_ERR, "ERROR: udp_init: out of memory\n"); |
123 | 123 |
goto error; |
124 | 124 |
} |
125 |
- |
|
125 |
+*/ |
|
126 | 126 |
if (init_su(addr, &sock_info->address, htons(sock_info->port_no))<0){ |
127 | 127 |
LOG(L_ERR, "ERROR: udp_init: could not init sockaddr_union\n"); |
128 | 128 |
goto error; |
129 | 129 |
} |
130 |
- /* |
|
131 |
- addr->sin_family=AF_INET; |
|
132 |
- addr->sin_port=htons(port); |
|
133 |
- addr->sin_addr.s_addr=ip; |
|
134 |
- */ |
|
135 |
- |
|
136 | 130 |
|
137 | 131 |
sock_info->socket = socket(AF2PF(addr->s.sa_family), SOCK_DGRAM, 0); |
138 | 132 |
if (sock_info->socket==-1){ |
... | ... |
@@ -158,17 +152,11 @@ int udp_init(struct socket_info* sock_info) |
158 | 152 |
|
159 | 153 |
|
160 | 154 |
if ( probe_max_receive_buffer(sock_info->socket)==-1) goto error; |
161 |
-#ifdef __FreeBSD__ |
|
162 |
- sock_len=addr->s.sa_len; |
|
163 |
-#else |
|
164 |
- sock_len=sizeof(union sockaddr_union); |
|
165 |
-#endif |
|
166 | 155 |
|
167 |
- |
|
168 |
- if (bind(sock_info->socket, &addr->s, sock_len)==-1){ |
|
156 |
+ if (bind(sock_info->socket, &addr->s, sockaddru_len(*addr))==-1){ |
|
169 | 157 |
LOG(L_ERR, "ERROR: udp_init: bind(%x, %p, %d) on %s: %s\n", |
170 | 158 |
sock_info->socket, &addr->s, |
171 |
- sock_len, |
|
159 |
+ sockaddru_len(*addr), |
|
172 | 160 |
sock_info->address_str.s, |
173 | 161 |
strerror(errno)); |
174 | 162 |
#ifdef USE_IPV6 |
... | ... |
@@ -179,11 +167,11 @@ int udp_init(struct socket_info* sock_info) |
179 | 167 |
goto error; |
180 | 168 |
} |
181 | 169 |
|
182 |
- free(addr); |
|
170 |
+/* free(addr);*/ |
|
183 | 171 |
return 0; |
184 | 172 |
|
185 | 173 |
error: |
186 |
- if (addr) free(addr); |
|
174 |
+/* if (addr) free(addr);*/ |
|
187 | 175 |
return -1; |
188 | 176 |
} |
189 | 177 |
|
... | ... |
@@ -207,6 +195,7 @@ int udp_rcv_loop() |
207 | 195 |
LOG(L_ERR, "ERROR: udp_rcv_loop: out of memory\n"); |
208 | 196 |
goto error; |
209 | 197 |
} |
198 |
+ memset(from, 0 , sizeof(union sockaddr_union)); |
|
210 | 199 |
|
211 | 200 |
for(;;){ |
212 | 201 |
#ifdef DYN_BUF |
... | ... |
@@ -217,7 +206,7 @@ int udp_rcv_loop() |
217 | 206 |
goto error; |
218 | 207 |
} |
219 | 208 |
#endif |
220 |
- fromlen=sizeof(union sockaddr_union); |
|
209 |
+ fromlen=sockaddru_len(bind_address->su); |
|
221 | 210 |
len=recvfrom(bind_address->socket, buf, BUF_SIZE, 0, &from->s, |
222 | 211 |
&fromlen); |
223 | 212 |
if (len==-1){ |
... | ... |
@@ -335,10 +324,11 @@ qa_passed: |
335 | 324 |
|
336 | 325 |
/* which socket to use? main socket or new one? */ |
337 | 326 |
int udp_send(struct socket_info *source, char *buf, unsigned len, |
338 |
- union sockaddr_union* to, unsigned tolen) |
|
327 |
+ union sockaddr_union* to) |
|
339 | 328 |
{ |
340 | 329 |
|
341 | 330 |
int n; |
331 |
+ int tolen; |
|
342 | 332 |
|
343 | 333 |
#ifdef DBG_MSG_QA |
344 | 334 |
/* aborts on error, does nothing otherwise */ |
... | ... |
@@ -348,7 +338,7 @@ int udp_send(struct socket_info *source, char *buf, unsigned len, |
348 | 338 |
} |
349 | 339 |
#endif |
350 | 340 |
|
351 |
- |
|
341 |
+ tolen=sockaddru_len(*to); |
|
352 | 342 |
again: |
353 | 343 |
n=sendto(source->socket, buf, len, 0, &to->s, tolen); |
354 | 344 |
#ifdef XL_DEBUG |