Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dbird committed Feb 18, 2011
1 parent 751da7e commit 416d1ac
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 121 deletions.
2 changes: 1 addition & 1 deletion conf/functions.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2006-2010 Coova Technologies, LLC.
# Copyright (c) 2006-2011 Coova Technologies, LLC.
# Licensed under Gnu General Public License.
# http://www.coova.org/
#
Expand Down
2 changes: 1 addition & 1 deletion conf/up.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ipt_in() {
[ -n "$UAMUIPORT" -a "$UAMUIPORT" != "0" ] && \
ipt_in -p tcp -m tcp --dport $UAMUIPORT --dst $ADDR -j ACCEPT

[ -n "HS_TCP_PORTS" ] && {
[ -n "$HS_TCP_PORTS" ] && {
for port in $HS_TCP_PORTS; do
ipt_in -p tcp -m tcp --dport $port --dst $ADDR -j ACCEPT
done
Expand Down
24 changes: 24 additions & 0 deletions doc/chilli_query.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,35 @@ idle time, input octets / max input octets, output octets / max output
octets, max total octets, status of option swapoctets, bandwidth
limitation information, and the original URL.

.TP
.BI listip " <ip-address>"
Same as
.B list
but for one IP address.

.TP
.BI listmac " <mac-address>"
Same as
.B list
but for one MAC address.

.TP
.BI authorize " <parameters>"
To explicity authorize a client, or change the session parameters of an already
authorized client, by setting a series of session parameters.

.TP
.BI listippool
Show the internal IP pool state.

.TP
.BI listgarden
Show the internal walled garden state.

.TP
.BI listradqueue
Show the internal RADIUS queue state.

.RS
.I PARAMETERS
.TP
Expand Down
64 changes: 28 additions & 36 deletions src/chilli.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,15 +614,6 @@ static inline int leaky_bucket(struct app_conn_t *conn, uint64_t octetsup, uint6
}
#endif


/* Run external script */
#define VAL_STRING 0
#define VAL_IN_ADDR 1
#define VAL_MAC_ADDR 2
#define VAL_ULONG 3
#define VAL_ULONG64 4
#define VAL_USHORT 5

int set_env(char *name, char type, void *value, int len) {
char *v=0;
char s[1024];
Expand Down Expand Up @@ -4827,20 +4818,20 @@ int chilli_cmd(struct cmdsock_request *req, bstring s, int sock) {
break;

case CMDSOCK_DHCP_DROP:
if (dhcp) dhcp_block_mac(dhcp, req->data.mac);
if (dhcp) dhcp_block_mac(dhcp, req->sess.mac);
break;

case CMDSOCK_LOGOUT:
if (req->data.sess.ip.s_addr || req->data.sess.sessionid[0]) {
if (req->sess.ip.s_addr || req->sess.sessionid[0]) {
struct app_conn_t *appconn = firstusedconn;

log_dbg("looking to logout session %s",
inet_ntoa(req->data.sess.ip));
inet_ntoa(req->sess.ip));

while (appconn) {
if (appconn->inuse &&
(req->data.sess.ip.s_addr == 0 || appconn->hisip.s_addr == req->data.sess.ip.s_addr) &&
(req->data.sess.sessionid[0] == 0 || !strcmp(appconn->s_state.sessionid, req->data.sess.sessionid))
(req->sess.ip.s_addr == 0 || appconn->hisip.s_addr == req->sess.ip.s_addr) &&
(req->sess.sessionid[0] == 0 || !strcmp(appconn->s_state.sessionid, req->sess.sessionid))
){
terminate_appconn(appconn, RADIUS_TERMINATE_CAUSE_ADMIN_RESET);
break;
Expand All @@ -4852,7 +4843,7 @@ int chilli_cmd(struct cmdsock_request *req, bstring s, int sock) {
/* else drop through */
case CMDSOCK_DHCP_RELEASE:
if (dhcp)
dhcp_release_mac(dhcp, req->data.mac,
dhcp_release_mac(dhcp, req->sess.mac,
RADIUS_TERMINATE_CAUSE_ADMIN_RESET);
break;

Expand Down Expand Up @@ -4896,13 +4887,13 @@ int chilli_cmd(struct cmdsock_request *req, bstring s, int sock) {
break;

case CMDSOCK_ENTRY_FOR_IP:
if (dhcp) dhcp_entry_for_ip(dhcp, s, &req->data.sess.ip,
if (dhcp) dhcp_entry_for_ip(dhcp, s, &req->sess.ip,
req->options & CMDSOCK_OPT_JSON ?
LIST_JSON_FMT : LIST_LONG_FMT);
break;

case CMDSOCK_ENTRY_FOR_MAC:
if (dhcp) dhcp_entry_for_mac(dhcp, s, req->data.mac,
if (dhcp) dhcp_entry_for_mac(dhcp, s, req->sess.mac,
req->options & CMDSOCK_OPT_JSON ?
LIST_JSON_FMT : LIST_LONG_FMT);
break;
Expand All @@ -4916,17 +4907,17 @@ int chilli_cmd(struct cmdsock_request *req, bstring s, int sock) {
case CMDSOCK_ROUTE_GW:
{
if (req->type == CMDSOCK_ROUTE_GW) {
log_dbg("setting route for idx %d", req->data.sess.params.routeidx);
copy_mac6(tun(tun, req->data.sess.params.routeidx).gwaddr, req->data.mac);
log_dbg("setting route for idx %d", req->sess.params.routeidx);
copy_mac6(tun(tun, req->sess.params.routeidx).gwaddr, req->sess.mac);
} else {
struct dhcp_conn_t *conn = dhcp->firstusedconn;
log_dbg("looking to alter session %s",inet_ntoa(req->data.sess.ip));
log_dbg("looking to alter session %s",inet_ntoa(req->sess.ip));
while (conn && conn->inuse) {
if (conn->peer) {
struct app_conn_t * appconn = (struct app_conn_t*)conn->peer;
if (!memcmp(appconn->hismac, req->data.mac, 6)) {
log_dbg("routeidx %s %d",appconn->s_state.sessionid, req->data.sess.params.routeidx);
appconn->s_params.routeidx = req->data.sess.params.routeidx;
if (!memcmp(appconn->hismac, req->sess.mac, 6)) {
log_dbg("routeidx %s %d",appconn->s_state.sessionid, req->sess.params.routeidx);
appconn->s_params.routeidx = req->sess.params.routeidx;
break;
}
}
Expand Down Expand Up @@ -5005,23 +4996,23 @@ int chilli_cmd(struct cmdsock_request *req, bstring s, int sock) {
* Redo this to using app firstfreeconn ...
*/
struct app_conn_t *appconn = firstusedconn;
log_dbg("looking to authorized session %s",inet_ntoa(req->data.sess.ip));
log_dbg("looking to authorized session %s",inet_ntoa(req->sess.ip));
while (appconn) {
if (appconn->inuse &&
(req->data.sess.ip.s_addr == 0 || appconn->hisip.s_addr == req->data.sess.ip.s_addr) &&
(req->data.sess.sessionid[0] == 0 || !strcmp(appconn->s_state.sessionid,req->data.sess.sessionid))
(req->sess.ip.s_addr == 0 || appconn->hisip.s_addr == req->sess.ip.s_addr) &&
(req->sess.sessionid[0] == 0 || !strcmp(appconn->s_state.sessionid,req->sess.sessionid))
){
char *uname = req->data.sess.username;
char *uname = req->sess.username;

log_dbg("remotely authorized session %s",appconn->s_state.sessionid);
memcpy(&appconn->s_params, &req->data.sess.params, sizeof(req->data.sess.params));
memcpy(&appconn->s_params, &req->sess.params, sizeof(req->sess.params));

if (uname[0]) safe_strncpy(appconn->s_state.redir.username, uname, USERNAMESIZE);
session_param_defaults(&appconn->s_params);

switch(req->type) {
case CMDSOCK_LOGIN:
auth_radius(appconn, uname, req->data.sess.password, 0, 0);
auth_radius(appconn, uname, req->sess.password, 0, 0);
break;
case CMDSOCK_AUTHORIZE:
dnprot_accept(appconn);
Expand All @@ -5035,24 +5026,24 @@ int chilli_cmd(struct cmdsock_request *req, bstring s, int sock) {
}
#else /* can likely be removed in favor of above */
struct dhcp_conn_t *dhcpconn = dhcp->firstusedconn;
log_dbg("looking to authorized session %s",inet_ntoa(req->data.sess.ip));
log_dbg("looking to authorized session %s",inet_ntoa(req->sess.ip));
while (dhcpconn && dhcpconn->inuse) {
if (dhcpconn->peer) {
struct app_conn_t * appconn = (struct app_conn_t*) dhcpconn->peer;
if ( (req->data.sess.ip.s_addr == 0 || appconn->hisip.s_addr == req->data.sess.ip.s_addr) &&
(req->data.sess.sessionid[0] == 0 || !strcmp(appconn->s_state.sessionid,req->data.sess.sessionid))
if ( (req->sess.ip.s_addr == 0 || appconn->hisip.s_addr == req->sess.ip.s_addr) &&
(req->sess.sessionid[0] == 0 || !strcmp(appconn->s_state.sessionid,req->sess.sessionid))
){
char *uname = req->data.sess.username;
char *uname = req->sess.username;

log_dbg("remotely authorized session %s",appconn->s_state.sessionid);
memcpy(&appconn->s_params, &req->data.sess.params, sizeof(req->data.sess.params));
memcpy(&appconn->s_params, &req->sess.params, sizeof(req->sess.params));

if (uname[0]) safe_strncpy(appconn->s_state.redir.username, uname, USERNAMESIZE);
session_param_defaults(&appconn->s_params);

switch(req->type) {
case CMDSOCK_LOGIN:
auth_radius(appconn, uname, req->data.sess.password, 0, 0);
auth_radius(appconn, uname, req->sess.password, 0, 0);
break;
case CMDSOCK_AUTHORIZE:
dnprot_accept(appconn);
Expand Down Expand Up @@ -5663,7 +5654,8 @@ int chilli_main(int argc, char **argv) {

net_select_reg(&sctx, radius->fd, SELECT_READ, (select_callback)radius_decaps, radius, 0);
#ifdef ENABLE_RADPROXY
net_select_reg(&sctx, radius->proxyfd, SELECT_READ, (select_callback)radius_proxy_ind, radius, 0);
if (radius->proxyfd)
net_select_reg(&sctx, radius->proxyfd, SELECT_READ, (select_callback)radius_proxy_ind, radius, 0);
#endif

#if defined(__linux__)
Expand Down
9 changes: 9 additions & 0 deletions src/chilli.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ struct app_conn_t {
char uamexit;
};

#define VAL_STRING 0
#define VAL_IN_ADDR 1
#define VAL_MAC_ADDR 2
#define VAL_ULONG 3
#define VAL_ULONG64 4
#define VAL_USHORT 5

int set_env(char *name, char type, void *value, int len);

extern struct app_conn_t *firstfreeconn; /* First free in linked list */
extern struct app_conn_t *lastfreeconn; /* Last free in linked list */
extern struct app_conn_t *firstusedconn; /* First used in linked list */
Expand Down
6 changes: 6 additions & 0 deletions src/chilli_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ int chilli_module_load(void **ctx, char *name) {
void *lib_handle;
char *error;
void *sym;
int len;

safe_snprintf(path, sizeof(path), "%s/%s.so",
_options.moddir ? _options.moddir : DEFLIBDIR, name);
Expand All @@ -38,6 +39,11 @@ int chilli_module_load(void **ctx, char *name) {
}

safe_snprintf(path, sizeof(path), "%s_module", name);

len = strlen(path);
while(len-- > 0)
if (path[len]=='-')
path[len] = '_';

sym = dlsym(lib_handle, path);
if ((error = dlerror()) != NULL) {
Expand Down
16 changes: 7 additions & 9 deletions src/cmdsock.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,14 @@
struct cmdsock_request {
uint16_t type;
uint16_t options;
union {
struct cmdsock_session {
unsigned char mac[PKT_ETH_ALEN];
struct cmdsock_session {
struct in_addr ip;
char username[256];
char password[256];
char sessionid[17];
struct session_params params;
} sess;
} data;
struct in_addr ip;
char username[256];
char password[256];
char sessionid[17];
struct session_params params;
} sess;
} __attribute__((packed));

typedef struct cmdsock_request CMDSOCK_REQUEST;
Expand Down
3 changes: 3 additions & 0 deletions src/main-opt.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ static const char *compile_options = "Compiled with "
#ifdef ENABLE_CHILLIPROXY
"ENABLE_CHILLIPROXY "
#endif
#ifdef ENABLE_RADPROXY
"ENABLE_RADPROXY "
#endif
#ifdef ENABLE_CHILLIRADSEC
"ENABLE_CHILLIRADSEC "
#endif
Expand Down
Loading

0 comments on commit 416d1ac

Please sign in to comment.