Merge branch 'master' of https://github.com/7u83/actube
FossilOrigin-Name: 3355f0c68623ed2e18dc5d5287c6e0039fe49bd13a95d7c56f7263f07e54c686
This commit is contained in:
commit
47e9660366
@ -389,7 +389,7 @@ static int init_listen_addrs()
|
||||
}
|
||||
|
||||
if (ifa->ifa_addr->sa_family == AF_INET && conf_ipv4) {
|
||||
sock_addrtostr(ifa->ifa_addr, str, 100);
|
||||
sock_addrtostr(ifa->ifa_addr, str, 100,1);
|
||||
*strchr(str, ':') = 0;
|
||||
conf_listen_addrs[ctr] =
|
||||
(char *) cw_setstr((uint8_t **) & conf_listen_addrs[ctr],
|
||||
@ -400,7 +400,7 @@ static int init_listen_addrs()
|
||||
}
|
||||
#ifdef WITH_IPV6
|
||||
if (ifa->ifa_addr->sa_family == AF_INET6 && conf_ipv6) {
|
||||
sock_addrtostr(ifa->ifa_addr, str, 100);
|
||||
sock_addrtostr(ifa->ifa_addr, str, 100,1);
|
||||
if (strncmp(str, "fe80:", 5) == 0) {
|
||||
strcat(str, "%");
|
||||
strcat(str, ifa->ifa_name);
|
||||
@ -496,7 +496,7 @@ int init_bcast_addrs()
|
||||
|
||||
char str[100];
|
||||
if (ifa->ifa_broadaddr) {
|
||||
sock_addrtostr(ifa->ifa_broadaddr, str, 100);
|
||||
sock_addrtostr(ifa->ifa_broadaddr, str, 100,1);
|
||||
*strchr(str, ':') = 0;
|
||||
stravltree_add(t, str);
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ int socklist_add_multicast(const char *addr, const char *port, int ac_proto)
|
||||
optlen = sizeof(mreq);
|
||||
|
||||
char sinin[100];
|
||||
sock_addrtostr((struct sockaddr *) sain, sinin, 100);
|
||||
sock_addrtostr((struct sockaddr *) sain, sinin, 100,1);
|
||||
|
||||
if (setsockopt(sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, opt, optlen)
|
||||
< 0) {
|
||||
|
@ -16,6 +16,10 @@
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Implements some aciplist functions
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -69,10 +73,12 @@ static void acip_del(void *d)
|
||||
free(d);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a cw_aciplist_t object
|
||||
* @return The created aciplist or NULL if an error has occured.
|
||||
*/
|
||||
cw_aciplist_t cw_aciplist_create()
|
||||
{
|
||||
return avltree_create(acip_cmp, acip_del);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
This file is part of libcapwap.
|
||||
This file is part of actube.
|
||||
|
||||
libcapwap is free software: you can redistribute it and/or modify
|
||||
actube is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
@ -28,14 +28,6 @@
|
||||
|
||||
int conn_send_packet(struct conn * conn, const uint8_t * buffer, int len)
|
||||
{
|
||||
/*
|
||||
#ifdef WITH_CW_LOG_DEBUG
|
||||
char addrstr[64];
|
||||
sock_addrtostr((struct sockaddr*)&conn->addr,addrstr,64);
|
||||
cw_log_debug1("Sending packet to %s, len=%d",addrstr,len);
|
||||
cw_log_debug2_dump(buffer,len,"Packet data for packet, sent to %s",addrstr);
|
||||
#endif
|
||||
*/
|
||||
int n;
|
||||
while((n=sendto( conn->sock, buffer, len, 0,
|
||||
(struct sockaddr*)&conn->addr,
|
||||
@ -43,6 +35,8 @@ int conn_send_packet(struct conn * conn, const uint8_t * buffer, int len)
|
||||
|
||||
if(errno == EINTR)
|
||||
continue;
|
||||
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
|
14
src/cw/cw.h
14
src/cw/cw.h
@ -16,7 +16,6 @@
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* Use some macros from LWAPP */
|
||||
|
||||
/**
|
||||
@ -43,9 +42,22 @@
|
||||
*/
|
||||
#define cw_put_data lw_put_data
|
||||
|
||||
/**
|
||||
* Put a bstr_t object
|
||||
* see #lw_put_bstr
|
||||
*/
|
||||
#define cw_put_bstr lw_put_bstr
|
||||
|
||||
/**
|
||||
* Put bstr16_t object
|
||||
* see #lw_put_bstr16
|
||||
*/
|
||||
#define cw_put_bstr16 lw_put_bstr16
|
||||
|
||||
/**
|
||||
* Set dword
|
||||
* see #lw_set_dword
|
||||
*/
|
||||
#define cw_set_dword lw_set_dword
|
||||
|
||||
#define cw_get_byte lw_get_byte
|
||||
|
@ -36,13 +36,30 @@ int cw_in_capwap_control_ipv4_address(struct conn *conn, struct cw_action_in *a,
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if (a->elem_id == CW_ELEM_CAPWAP_CONTROL_IPV4_ADDRESS) {
|
||||
struct sockaddr_in addr;
|
||||
memcpy(&addr.sin_addr,data,4);
|
||||
addr.sin_family=AF_INET;
|
||||
sock_setport((struct sockaddr*)&addr,CAPWAP_CONTROL_PORT);
|
||||
memcpy(&acip->ip,&addr,sizeof(addr));
|
||||
|
||||
acip->wtp_count = cw_get_word(data+4);
|
||||
}
|
||||
|
||||
if (a->elem_id == CW_ELEM_CAPWAP_CONTROL_IPV6_ADDRESS) {
|
||||
struct sockaddr_in6 addr;
|
||||
memset (&addr,0,sizeof(addr));
|
||||
memcpy(&addr.sin6_addr,data,16);
|
||||
addr.sin6_family=AF_INET6;
|
||||
sock_setport((struct sockaddr*)&addr,CAPWAP_CONTROL_PORT);
|
||||
memcpy(&acip->ip,&addr,sizeof(addr));
|
||||
acip->wtp_count = cw_get_word(data+16);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cw_aciplist_replace(list,acip);
|
||||
|
||||
|
||||
|
@ -15,6 +15,13 @@
|
||||
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief DTLS functions specific to gnutls
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
@ -42,7 +49,6 @@ ssize_t dtls_gnutls_bio_read(gnutls_transport_ptr_t b, void *out, size_t maxlen)
|
||||
|
||||
ssize_t dtls_gnutls_bio_write(gnutls_transport_ptr_t b, const void *data, size_t len)
|
||||
{
|
||||
|
||||
struct conn *conn = (struct conn*)b;
|
||||
return dtls_bio_write(conn,data,len);
|
||||
}
|
||||
|
@ -14,7 +14,8 @@
|
||||
int dtls_gnutls_connect(struct conn *conn)
|
||||
{
|
||||
struct dtls_gnutls_data *d;
|
||||
d = dtls_gnutls_data_create(conn,GNUTLS_CLIENT | GNUTLS_DATAGRAM | GNUTLS_NONBLOCK);
|
||||
d = dtls_gnutls_data_create(conn,
|
||||
GNUTLS_CLIENT | GNUTLS_DATAGRAM | GNUTLS_NONBLOCK);
|
||||
|
||||
// gnutls_dh_set_prime_bits(d->session, 512);
|
||||
#if GNUTLS_VERSION_NUMBER >= 0x030100
|
||||
@ -31,7 +32,8 @@ int dtls_gnutls_connect(struct conn *conn)
|
||||
|
||||
|
||||
if (rc < 0) {
|
||||
cw_log(LOG_ERR,"Can't connect: %s",gnutls_strerror(rc));
|
||||
cw_log(LOG_ERR, "DTLS (gnutls) Can't connect to %s: %s",
|
||||
sock_addr2str(&conn->addr), gnutls_strerror(rc));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -45,4 +47,3 @@ int dtls_gnutls_connect(struct conn *conn)
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -50,6 +50,10 @@
|
||||
#define lw_set_word(dst,b) \
|
||||
(*((uint16_t*)(dst)) = htons(w))
|
||||
|
||||
/**
|
||||
* Same as #lw_put_dword, but the return value
|
||||
* is unspecified.
|
||||
*/
|
||||
#define lw_set_dword(dst,dw)\
|
||||
(*((uint32_t*)(dst)) = htonl(dw))
|
||||
|
||||
|
@ -47,9 +47,13 @@
|
||||
* Defines the structure of an AVL Node.
|
||||
*/
|
||||
struct mavlnode {
|
||||
/** Pointer to data, thant belongs to the node */
|
||||
void *data;
|
||||
/** Pointer to left son*/
|
||||
struct mavlnode *left;
|
||||
/** Pointer to right son*/
|
||||
struct mavlnode *right;
|
||||
/** AVL balance */
|
||||
int bal;
|
||||
};
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
This file is part of libcapwap.
|
||||
This file is part of actube.
|
||||
|
||||
libcapwap is free software: you can redistribute it and/or modify
|
||||
actube is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
@ -16,6 +16,7 @@
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
*@file
|
||||
*@breif
|
||||
@ -55,7 +56,7 @@ extern int sock_getifaddr(const char *ifname, int family, int type, struct socka
|
||||
extern int sock_getifhwaddr(const char *ifname, uint8_t * hwaddr, uint8_t * addrlen);
|
||||
extern char *sock_hwaddrtostr(const uint8_t * haddr, int len, char *dst,
|
||||
const char *separator);
|
||||
extern char *sock_addrtostr(const struct sockaddr *sa, char *s, size_t maxlen);
|
||||
//extern char *sock_addrtostr(const struct sockaddr *sa, char *s, size_t maxlen);
|
||||
extern int sock_strtoaddr(const char *s, struct sockaddr *saout);
|
||||
extern int sock_set_recvtimeout(int sock, int seconds);
|
||||
|
||||
@ -74,16 +75,37 @@ extern int sock_getifinfo(const struct sockaddr *addr, char *ifname,
|
||||
|
||||
|
||||
|
||||
char *sock_strsockaddr(const struct sockaddr *sa, char *s, size_t maxlen, int addport);
|
||||
int sock_parse_ip_address ( const char** ppszText,
|
||||
unsigned char* abyAddr, int* pnPort, int* pbIsIPv6 );
|
||||
char *sock_addrtostr(const struct sockaddr *sa, char *s, size_t maxlen, int addport);
|
||||
|
||||
|
||||
/**
|
||||
* Convert a sockaddr structure to a human readable string
|
||||
* @param s sockaddr
|
||||
* @return A char* pointer to converted address
|
||||
*
|
||||
* The returned string is pushed on the stack (unnamed variable), so this macro should
|
||||
* only be used as function argument.
|
||||
*
|
||||
* Example:
|
||||
* \code
|
||||
struct sockaddr sa;
|
||||
// Initialize sa ...
|
||||
sprintf("Adress: %s",sock_addr2str(&sa));
|
||||
\endcode
|
||||
*/
|
||||
#define sock_addr2str(s) ( sock_addrtostr( (struct sockaddr*)s, (char[64]){0}, 64, 0 ) )
|
||||
|
||||
/**
|
||||
* Same as #sock_addr2str, but also the port number is appended to the result
|
||||
* @see #sock_addr2str
|
||||
*/
|
||||
#define sock_addr2str_p(s) ( sock_addrtostr( (struct sockaddr*)s, (char[64]){0}, 64,1 ) )
|
||||
|
||||
|
||||
|
||||
#define sock_addr2str(s) ( sock_strsockaddr( (struct sockaddr*)s, (char[64]){0}, 64,0 ) )
|
||||
#define sock_hwaddr2str(s,l) ( sock_hwaddrtostr( s,l, (char[64]){0}, ":" ) )
|
||||
#define sock_hwaddr2idstr(s,l) ( sock_hwaddrtostr( s,l, (char[64]){0}, "" ) )
|
||||
#define sock_addrtostr(s,str,n) sock_strsockaddr(s,str,n,1)
|
||||
//#define sock_addrtostr(s,str,n) sock_addrtostr(s,str,n,1)
|
||||
|
||||
#define sock_addrfamily(addr) ( ((struct sockaddr_storage*)(addr))->ss_family )
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
This file is part of libcapwap.
|
||||
This file is part of actube.
|
||||
|
||||
libcapwap is free software: you can redistribute it and/or modify
|
||||
actube is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
@ -15,6 +15,17 @@
|
||||
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief implements sock_addrtostr
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup sock
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@ -32,45 +43,47 @@
|
||||
|
||||
#include "sock.h"
|
||||
|
||||
/*
|
||||
void sock_hwaddrtostr(const uint8_t *haddr,int len,char *dst)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<len-1; i++){
|
||||
sprintf(dst,"%02X:",haddr[i]);
|
||||
dst+=3;
|
||||
}
|
||||
sprintf(dst,"%02X",haddr[i]);
|
||||
|
||||
}
|
||||
/**
|
||||
* Convert a struct sockaddr int to a human readable string.
|
||||
* @param sa sockaddr to convert
|
||||
* @param s Destination buffer
|
||||
* @param maxlen Size of destination buffer
|
||||
* @param addport If true then the port number wil be added to the output
|
||||
*
|
||||
* Works only for sockaddrs of type AF_INET, AF_INET6, AF_PACKET, AF_LINK.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
char *sock_strsockaddr(const struct sockaddr *sa, char *s, size_t maxlen,int addport)
|
||||
char *sock_addrtostr(const struct sockaddr *sa, char *s, size_t maxlen, int addport)
|
||||
{
|
||||
|
||||
char d[maxlen];
|
||||
int port;
|
||||
|
||||
|
||||
switch (sa->sa_family) {
|
||||
case AF_INET:
|
||||
inet_ntop(AF_INET, &(((struct sockaddr_in *)sa)->sin_addr), s, maxlen);
|
||||
inet_ntop(AF_INET, &(((struct sockaddr_in *) sa)->sin_addr), d,
|
||||
maxlen);
|
||||
if (addport) {
|
||||
port = ((struct sockaddr_in *) sa)->sin_port;
|
||||
if (addport)
|
||||
sprintf(s,"%s:%i",s,ntohs(port));
|
||||
else
|
||||
sprintf(s,"%s",s);
|
||||
sprintf(s, "%s:%i", d, ntohs(port));
|
||||
} else
|
||||
sprintf(s, "%s", d);
|
||||
break;
|
||||
|
||||
case AF_INET6:
|
||||
inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)sa)->sin6_addr), s, maxlen);
|
||||
inet_ntop(AF_INET6, &(((struct sockaddr_in6 *) sa)->sin6_addr), d,
|
||||
maxlen);
|
||||
if (addport) {
|
||||
port = ((struct sockaddr_in6 *) sa)->sin6_port;
|
||||
sprintf(s, "[%s]:%i", d, ntohs(port));
|
||||
} else
|
||||
sprintf(s, "%s", d);
|
||||
break;
|
||||
#ifdef AF_LINK
|
||||
case AF_LINK:
|
||||
{
|
||||
struct sockaddr_dl *sl = (struct sockaddr_dl *) sa;
|
||||
sock_hwaddrtostr(((uint8_t*)sl->sdl_data)+sl->sdl_nlen,sl->sdl_alen,s,":");
|
||||
sock_hwaddrtostr(((uint8_t *) sl->sdl_data) + sl->sdl_nlen,
|
||||
sl->sdl_alen, s, ":");
|
||||
|
||||
}
|
||||
break;
|
||||
@ -99,3 +112,7 @@ char *sock_strsockaddr(const struct sockaddr *sa, char *s, size_t maxlen,int add
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
@ -1,21 +1,59 @@
|
||||
/*
|
||||
This file is part of actube.
|
||||
|
||||
actube is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
libcapwap is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#include "sock.h"
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief implements sock_setport
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup SOCK
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Set the port number of a sockaddr
|
||||
* @param addr sockaddr where the port will be set
|
||||
* @param port number
|
||||
* @return 1 if successful, otherwise 0
|
||||
* Ports can only be set for sockaddrs of type AF_INET and AF_INET6
|
||||
*/
|
||||
int sock_setport(struct sockaddr *addr, int port)
|
||||
{
|
||||
switch (addr->sa_family){
|
||||
case AF_INET:
|
||||
((struct sockaddr_in*)addr)->sin_port=htons(port);
|
||||
break;
|
||||
#ifdef WITH_IPV6
|
||||
case AF_INET6:
|
||||
((struct sockaddr_in6*)addr)->sin6_port=htonl(port);
|
||||
((struct sockaddr_in6*)addr)->sin6_port=htons(port);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
@ -73,6 +73,9 @@ cw_aciplist_t cw_select_ac(struct conn *conn, mbag_t dis)
|
||||
|
||||
DEFINE_AVLITER(i, dis);
|
||||
avliter_foreach(&i){
|
||||
|
||||
|
||||
|
||||
mbag_t ac = ((mbag_item_t *) (avliter_get(&i)))->data;
|
||||
|
||||
char *ac_name = mbag_get_str(ac, CW_ITEM_AC_NAME,NULL);
|
||||
@ -92,9 +95,17 @@ printf("nprio: %d\n",priolist->count);
|
||||
cw_aciplist_t acips =
|
||||
mbag_get_mavl(ac, CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST);
|
||||
|
||||
printf("Number of acips =%d\n",acips->count);
|
||||
|
||||
|
||||
DEFINE_AVLITER(i2, acips);
|
||||
avliter_foreach(&i2){
|
||||
|
||||
|
||||
cw_acip_t *acip = avliter_get(&i2);
|
||||
|
||||
printf("The acip: %s\n",sock_addr2str(&acip->ip));
|
||||
|
||||
cw_acip_t *n = malloc(sizeof(cw_acip_t));
|
||||
memcpy(n,acip,sizeof(cw_acip_t));
|
||||
|
||||
|
@ -102,14 +102,16 @@ int run_join_d(struct sockaddr *sa)
|
||||
int sockfd;
|
||||
int rc;
|
||||
|
||||
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
sockfd = socket(sa->sa_family, SOCK_DGRAM, 0);
|
||||
if (sockfd == -1) {
|
||||
cw_log(LOG_ERR, "Can't create socket: %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
sock_set_recvtimeout(sockfd, 1);
|
||||
conn->sock = sockfd;
|
||||
sock_copyaddr(&conn->addr, sa);
|
||||
|
||||
rc = connect(sockfd, (struct sockaddr *) sa,
|
||||
/* rc = connect(sockfd, (struct sockaddr *) sa,
|
||||
sock_addrlen((struct sockaddr *) sa));
|
||||
|
||||
if (rc < 0) {
|
||||
@ -118,9 +120,7 @@ int run_join_d(struct sockaddr *sa)
|
||||
close(sockfd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
conn->sock = sockfd;
|
||||
sock_copyaddr(&conn->addr, sa);
|
||||
*/
|
||||
|
||||
cw_dbg(DBG_DTLS, "Establishing DTLS session with %s", sock_addr2str(sa));
|
||||
|
||||
@ -153,7 +153,7 @@ int run_join_d(struct sockaddr *sa)
|
||||
rc = dtls_connect(conn);
|
||||
if (rc != 1) {
|
||||
dtls_shutdown(conn);
|
||||
cw_log(LOG_ERR, "Can't establish DTLS connection to %s",
|
||||
cw_log(LOG_ERR, "Can't establish DTLS connection with %s",
|
||||
sock_addr2str(sa));
|
||||
close(sockfd);
|
||||
return 0;
|
||||
@ -226,12 +226,15 @@ int join()
|
||||
|
||||
cw_acip_t *ip = avliter_get(&ii);
|
||||
|
||||
|
||||
cw_dbg(DBG_INFO, "Going to join CAWAP controller on %s",
|
||||
sock_addr2str(&ip->ip));
|
||||
sock_addr2str_p(&ip->ip));
|
||||
|
||||
int rc = run_join_d((struct sockaddr *) &ip->ip);
|
||||
if (!rc)
|
||||
|
||||
if (rc<=0)
|
||||
continue;
|
||||
|
||||
rc = run_join(conn);
|
||||
if (rc) {
|
||||
conn->capwap_state = CW_STATE_CONFIGURE;
|
||||
|
Loading…
Reference in New Issue
Block a user