make log a conditional macro for _log
authorBrendan O'Dea <bod@optus.net>
Wed, 3 Nov 2004 13:23:58 +0000 (13:23 +0000)
committerBrendan O'Dea <bod@optus.net>
Wed, 3 Nov 2004 13:23:58 +0000 (13:23 +0000)
autosnoop.c
autothrottle.c
garden.c
l2tpns.c
l2tpns.h
plugin.h

index 7ab4321..3fdb882 100644 (file)
@@ -23,12 +23,12 @@ int plugin_radius_response(struct param_radius_response *data)
                        if (*data->value) data->s->snoop_ip = inet_addr(data->value);
                        if (data->s->snoop_ip == INADDR_NONE) data->s->snoop_ip = 0;
                        if (*x) data->s->snoop_port = atoi(x);
-                       p->log(3, 0, 0, 0, "         Intercepting user to %s:%d\n",
+                       p->_log(3, 0, 0, 0, "         Intercepting user to %s:%d\n",
                                p->inet_toa(data->s->snoop_ip), data->s->snoop_port);
                }
                else
                {
-                       p->log(3, 0, 0, 0, "         Not Intercepting user (reply string should be snoop=ip:port)\n");
+                       p->_log(3, 0, 0, 0, "         Not Intercepting user (reply string should be snoop=ip:port)\n");
                }
        }
        return PLUGIN_RET_OK;
index 65f3ff7..ce47d9d 100644 (file)
@@ -36,17 +36,17 @@ int plugin_radius_response(struct param_radius_response *data)
                                        case 2: // output
                                                data->s->throttle_out = rate;
                                                free(pt);
-                                               p->log(3, 0, p->get_id_by_session(data->s), data->s->tunnel, "      Set output throttle rate %dkb/s\n", rate);
+                                               p->_log(3, 0, p->get_id_by_session(data->s), data->s->tunnel, "      Set output throttle rate %dkb/s\n", rate);
                                                return PLUGIN_RET_OK;
 
                                        case 3: //input
                                                data->s->throttle_in = rate;
                                                free(pt);
-                                               p->log(3, 0, p->get_id_by_session(data->s), data->s->tunnel, "      Set input throttle rate %dkb/s\n", rate);
+                                               p->_log(3, 0, p->get_id_by_session(data->s), data->s->tunnel, "      Set input throttle rate %dkb/s\n", rate);
                                                return PLUGIN_RET_OK;
 
                                        default:
-                                               p->log(1, 0, p->get_id_by_session(data->s), data->s->tunnel, "Syntax error in rate limit AV pair: %s=%s\n", data->key, data->value);
+                                               p->_log(1, 0, p->get_id_by_session(data->s), data->s->tunnel, "Syntax error in rate limit AV pair: %s=%s\n", data->key, data->value);
                                                free(pt);
                                                return PLUGIN_RET_OK;
                                }
@@ -54,7 +54,7 @@ int plugin_radius_response(struct param_radius_response *data)
                        else
                        {
                                free(pt);
-                               p->log(1, 0, p->get_id_by_session(data->s), data->s->tunnel, "Syntax error in rate limit AV pair: %s=%s\n",
+                               p->_log(1, 0, p->get_id_by_session(data->s), data->s->tunnel, "Syntax error in rate limit AV pair: %s=%s\n",
                                        data->key, data->value);
                                return PLUGIN_RET_OK;
                        }
@@ -65,17 +65,17 @@ int plugin_radius_response(struct param_radius_response *data)
        {
                if (strcmp(data->value, "yes") == 0)
                {
-                       p->log(3, 0, p->get_id_by_session(data->s), data->s->tunnel, "         Throttling user\n");
+                       p->_log(3, 0, p->get_id_by_session(data->s), data->s->tunnel, "         Throttling user\n");
                        data->s->throttle_in = data->s->throttle_out = config->rl_rate;
                }
                else if (strcmp(data->value, "no") == 0)
                {
-                       p->log(3, 0, p->get_id_by_session(data->s), data->s->tunnel, "         Not throttling user\n");
+                       p->_log(3, 0, p->get_id_by_session(data->s), data->s->tunnel, "         Not throttling user\n");
                        data->s->throttle_in = data->s->throttle_out = 0;
                }
        }
 
-       p->log(4, 0, p->get_id_by_session(data->s), data->s->tunnel, "autothrottle module ignoring AV pair %s=%s\n",
+       p->_log(4, 0, p->get_id_by_session(data->s), data->s->tunnel, "autothrottle module ignoring AV pair %s=%s\n",
                data->key, data->value);
 
        return PLUGIN_RET_OK;
index 89cc78d..b0abf21 100644 (file)
--- a/garden.c
+++ b/garden.c
@@ -7,7 +7,7 @@
 #include "plugin.h"
 #include "control.h"
 
-char const *cvs_id = "$Id: garden.c,v 1.8 2004-10-30 07:35:31 bodea Exp $";
+char const *cvs_id = "$Id: garden.c,v 1.9 2004-11-03 13:23:58 bodea Exp $";
 
 int __plugin_api_version = 1;
 static struct pluginfuncs *p = 0;
@@ -45,7 +45,7 @@ int plugin_post_auth(struct param_post_auth *data)
        // Ignore if user authentication was successful
        if (data->auth_allowed) return PLUGIN_RET_OK;
 
-       p->log(3, 0, 0, 0, "Walled Garden allowing login\n");
+       p->_log(3, 0, 0, 0, "Walled Garden allowing login\n");
        data->auth_allowed = 1;
        data->s->walled_garden = 1;
        return PLUGIN_RET_OK;
@@ -100,7 +100,7 @@ int plugin_control(struct param_control *data)
                sprintf((data->response + data->response_length), "%s", errormsg);
                data->response_length += strlen(errormsg) + 1;
 
-               p->log(3, 0, 0, 0, "Unknown session %d\n", session);
+               p->_log(3, 0, 0, 0, "Unknown session %d\n", session);
                return PLUGIN_RET_STOP;
        }
        *(short *)(data->response + 2) = ntohs(PKT_RESP_OK);
@@ -123,7 +123,7 @@ int plugin_become_master(void)
 
        for (i = 0; up_commands[i] && *up_commands[i]; i++)
        {
-               p->log(3, 0, 0, 0, "Running %s\n", up_commands[i]);
+               p->_log(3, 0, 0, 0, "Running %s\n", up_commands[i]);
                system(up_commands[i]);
        }
 
@@ -148,9 +148,9 @@ int garden_session(sessiont *s, int flag)
 
        if (flag == 1)
        {
-               p->log(2, 0, 0, s->tunnel, "Garden user %s (%s)\n", s->user, p->inet_toa(htonl(s->ip)));
+               p->_log(2, 0, 0, s->tunnel, "Garden user %s (%s)\n", s->user, p->inet_toa(htonl(s->ip)));
                snprintf(cmd, sizeof(cmd), "iptables -t nat -A garden_users -s %s -j garden", p->inet_toa(htonl(s->ip)));
-               p->log(3, 0, 0, s->tunnel, "%s\n", cmd);
+               p->_log(3, 0, 0, s->tunnel, "%s\n", cmd);
                system(cmd);
                s->walled_garden = 1;
        }
@@ -160,7 +160,7 @@ int garden_session(sessiont *s, int flag)
                int count = 40;
 
                // Normal User
-               p->log(2, 0, 0, s->tunnel, "Un-Garden user %s (%s)\n", s->user, p->inet_toa(htonl(s->ip)));
+               p->_log(2, 0, 0, s->tunnel, "Un-Garden user %s (%s)\n", s->user, p->inet_toa(htonl(s->ip)));
                // Kick off any duplicate usernames
                // but make sure not to kick off ourself
                if (s->ip && !s->die && (other = p->get_session_by_username(s->user)) && s != p->get_session_by_id(other)) {
@@ -171,7 +171,7 @@ int garden_session(sessiont *s, int flag)
                s->pin = s->pout = 0;
 
                snprintf(cmd, sizeof(cmd), "iptables -t nat -D garden_users -s %s -j garden", p->inet_toa(htonl(s->ip)));
-               p->log(3, 0, 0, s->tunnel, "%s\n", cmd);
+               p->_log(3, 0, 0, s->tunnel, "%s\n", cmd);
                while (--count)
                {
                        int status = system(cmd);
@@ -215,7 +215,7 @@ int plugin_init(struct pluginfuncs *funcs)
                int i;
                for (i = 0; down_commands[i] && *down_commands[i]; i++)
                {
-                       p->log(3, 0, 0, 0, "Running %s\n", down_commands[i]);
+                       p->_log(3, 0, 0, 0, "Running %s\n", down_commands[i]);
                        system(down_commands[i]);
                }
        }
@@ -232,7 +232,7 @@ void plugin_done()
 
        for (i = 0; down_commands[i] && *down_commands[i]; i++)
        {
-               p->log(3, 0, 0, 0, "Running %s\n", down_commands[i]);
+               p->_log(3, 0, 0, 0, "Running %s\n", down_commands[i]);
                system(down_commands[i]);
        }
 }
index d03ba2b..d95517e 100644 (file)
--- a/l2tpns.c
+++ b/l2tpns.c
@@ -4,7 +4,7 @@
 // Copyright (c) 2002 FireBrick (Andrews & Arnold Ltd / Watchfront Ltd) - GPL licenced
 // vim: sw=8 ts=8
 
-char const *cvs_id_l2tpns = "$Id: l2tpns.c,v 1.38 2004-11-02 06:45:03 bodea Exp $";
+char const *cvs_id_l2tpns = "$Id: l2tpns.c,v 1.39 2004-11-03 13:23:58 bodea Exp $";
 
 #include <arpa/inet.h>
 #include <assert.h>
@@ -239,7 +239,7 @@ void _log(int level, ipt address, sessionidt s, tunnelidt t, const char *format,
        va_end(ap);
 }
 
-void _log_hex(int level, ipt address, sessionidt s, tunnelidt t, const char *title, const char *data, int maxsize)
+void _log_hex(int level, const char *title, const char *data, int maxsize)
 {
        int i, j;
        const u8 *d = (const u8 *)data;
@@ -249,7 +249,7 @@ void _log_hex(int level, ipt address, sessionidt s, tunnelidt t, const char *tit
        // No support for log_hex to syslog
        if (log_stream)
        {
-               log(level, address, s, t, "%s (%d bytes):\n", title, maxsize);
+               _log(level, 0, 0, 0, "%s (%d bytes):\n", title, maxsize);
                setvbuf(log_stream, NULL, _IOFBF, 16384);
 
                for (i = 0; i < maxsize; )
index 446abdf..723579f 100644 (file)
--- a/l2tpns.h
+++ b/l2tpns.h
@@ -1,5 +1,5 @@
 // L2TPNS Global Stuff
-// $Id: l2tpns.h,v 1.27 2004-11-02 23:43:52 bodea Exp $
+// $Id: l2tpns.h,v 1.28 2004-11-03 13:23:59 bodea Exp $
 
 #ifndef __L2TPNS_H__
 #define __L2TPNS_H__
@@ -539,12 +539,14 @@ int cmd_show_ipcache(struct cli_def *cli, char *command, char **argv, int argc);
 int cmd_show_hist_idle(struct cli_def *cli, char *command, char **argv, int argc);
 int cmd_show_hist_open(struct cli_def *cli, char *command, char **argv, int argc);
 
-#define log _log
-#ifndef log_hex
-#define log_hex(a,b,c,d) do{if (a <= config->debug) _log_hex(a,0,0,0,b,c,d);}while (0)
-#endif
+#undef log
+#undef log_hex
+#define log(D, a, s, t, f, ...)        ({ if (D <= config->debug) _log(D, a, s, t, f, ## __VA_ARGS__); })
+#define log_hex(D, t, d, s)    ({ if (D <= config->debug) _log_hex(D, t, d, s); })
+
 void _log(int level, ipt address, sessionidt s, tunnelidt t, const char *format, ...) __attribute__((format (printf, 5, 6)));
-void _log_hex(int level, ipt address, sessionidt s, tunnelidt t, const char *title, const char *data, int maxsize);
+void _log_hex(int level, const char *title, const char *data, int maxsize);
+
 void build_chap_response(char *challenge, u8 id, u16 challenge_length, char **challenge_response);
 int sessionsetup(tunnelidt t, sessionidt s);
 int cluster_send_session(int s);
index 896f08e..f0a7a5f 100644 (file)
--- a/plugin.h
+++ b/plugin.h
@@ -26,7 +26,7 @@ enum
 struct pluginfuncs
 {
        void (*_log)(int level, ipt address, sessionidt s, tunnelidt t, const char *format, ...);
-       void (*_log_hex)(int level, ipt address, sessionidt s, tunnelidt t, const char *title, const char *data, int maxsize);
+       void (*_log_hex)(int level, const char *title, const char *data, int maxsize);
        char *(*inet_toa)(unsigned long addr);
        sessionidt (*get_session_by_username)(char *username);
        sessiont *(*get_session_by_id)(sessionidt s);