contrib/fwd: remove debug prints, add syslog info
authorJo-Philipp Wich <jow@openwrt.org>
Sun, 20 Dec 2009 02:57:31 +0000 (02:57 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Sun, 20 Dec 2009 02:57:31 +0000 (02:57 +0000)
contrib/fwd/src/fwd.c
contrib/fwd/src/fwd_config.c
contrib/fwd/src/fwd_rules.c

index 0b25cb03816756cd6947cc93fa57f2296d832ae6..662524e3587d9d240fc3ac9402d9b4ae1c46aa30 100644 (file)
@@ -106,19 +106,31 @@ static int fwd_server_main(int argc, const char *argv[])
 
                                        if( !fwd_empty_cidr(addr_new) && fwd_empty_cidr(addr_old) )
                                        {
-                                               printf("IFUP[%s]\n", net->ifname);
+                                               fwd_log_info(
+                                                       "Interface %s brought up - adding rules",
+                                                       net->ifname
+                                               );
+
                                                fwd_update_cidr(addr_old, addr_new);
                                                fwd_ipt_addif(h, net->name);
                                        }
                                        else if( fwd_empty_cidr(addr_new) && !fwd_empty_cidr(addr_old) )
                                        {
-                                               printf("IFDOWN[%s]\n", net->ifname);
+                                               fwd_log_info(
+                                                       "Interface %s went down - removing rules",
+                                                       net->ifname
+                                               );
+
                                                fwd_update_cidr(addr_old, NULL);
                                                fwd_ipt_delif(h, net->name);
                                        }
                                        else if( ! fwd_equal_cidr(addr_old, addr_new) )
                                        {
-                                               printf("IFCHANGE[%s]\n", net->ifname);
+                                               fwd_log_info(
+                                                       "Interface %s changed IP - rebuilding rules",
+                                                       net->ifname
+                                               );
+
                                                fwd_update_cidr(addr_old, addr_new);
                                                fwd_ipt_chgif(h, net->name);
                                        }
index def36d139cd970db14788492701cbc3af45072a2..320e9ffca0ff9ac09ff5c3a9c6a2ac34fe1a8421 100644 (file)
 #include "ucix.h"
 
 
-#define fwd_read_error(...) do {  \
-       fprintf(stderr, "ERROR: ");   \
-       fprintf(stderr, __VA_ARGS__); \
-       fprintf(stderr, "\n");        \
-       return;                       \
+#define fwd_read_error(...) do { \
+       fwd_log_err(__VA_ARGS__);    \
+       return;                      \
 } while(0)
 
 
index 3e7314f36285cc50e44e547693302dd81697206a..b960e62fdb24f28cc19e9e1cd8da85e01fc97d8d 100644 (file)
@@ -496,12 +496,13 @@ void fwd_ipt_build_ruleset(struct fwd_handle *h)
                switch(e->type)
                {
                        case FWD_S_DEFAULTS:
-                               printf("\n## DEFAULTS\n");
+                               fwd_log_info("Loading defaults");
                                fwd_ipt_defaults_create(e);
                                break;
 
                        case FWD_S_INCLUDE:
-                               printf("\n## INCLUDE %s\n", e->section.include.path);
+                               fwd_log_info("Loading include: %s",
+                                       e->section.include.path);
                                break;
 
                        case FWD_S_ZONE:
@@ -573,13 +574,12 @@ void fwd_ipt_addif(struct fwd_handle *h, const char *net)
                return;
 
 
-       printf("\n\n#\n# addif(%s)\n#\n", net);
+       fwd_log_info("Adding network %s (interface %s)",
+               n->name, n->ifname);
 
        /* Build masquerading rule */
        if( z->masq )
        {
-               printf("\n# Net %s (%s) - masq\n", n->name, n->ifname);
-
                if( (x = fwd_xt_init_rule(h_nat)) != NULL )
                {
                        fwd_xt_parse_out(x, n, 0);                              /* -o ... */
@@ -592,8 +592,6 @@ void fwd_ipt_addif(struct fwd_handle *h, const char *net)
        /* Build MSS fix rule */
        if( z->mtu_fix )
        {
-               printf("\n# Net %s (%s) - mtu_fix\n", n->name, n->ifname);
-
                if( (x = fwd_xt_init_rule(h_filter)) != NULL )
                {
                        p.type = FWD_PR_TCP;
@@ -621,11 +619,6 @@ void fwd_ipt_addif(struct fwd_handle *h, const char *net)
        {
                if( (a2 = n2->addr) != NULL )
                {
-                       printf("\n# Net %s (%s) - intra-zone-forwarding"
-                              " Z:%s N:%s I:%s -> Z:%s N:%s I:%s\n",
-                               n->name, n->ifname, z->name, n->name, n->ifname,
-                               z->name, n2->name, n2->ifname);
-
                        if( (x = fwd_xt_init_rule(h_filter)) != NULL )
                        {
                                fwd_xt_parse_in(x, n, 0);                               /* -i ... */
@@ -642,11 +635,6 @@ void fwd_ipt_addif(struct fwd_handle *h, const char *net)
        {
                for( n2 = f->dest->networks; n2; n2 = n2->next )
                {
-                       printf("\n# Net %s (%s) - inter-zone-forwarding"
-                   " Z:%s N:%s I:%s -> Z:%s N:%s I:%s\n",
-                               n->name, n->ifname, z->name, n->name, n->ifname,
-                               f->dest->name, n2->name, n2->ifname);
-
                        /* Build forwarding rule */
                        if( (x = fwd_xt_init_rule(h_filter)) != NULL )
                        {
@@ -662,9 +650,6 @@ void fwd_ipt_addif(struct fwd_handle *h, const char *net)
        /* Build DNAT rules */
        for( e = z->redirects; e && (r = &e->section.redirect); e = e->next )
        {
-               printf("\n# Net %s (%s) - redirect Z:%s N:%s I:%s\n",
-                       n->name, n->ifname, z->name, n->name, n->ifname);
-
                /* DNAT */
                if( (x = fwd_xt_init_rule(h_nat)) != NULL )
                {
@@ -720,11 +705,6 @@ void fwd_ipt_addif(struct fwd_handle *h, const char *net)
                {
                        for( n2 = c->dest->networks; n2; n2 = n2->next )
                        {
-                               printf("\n# Net %s (%s) - rule+dest"
-                              " Z:%s N:%s I:%s -> Z:%s N:%s I:%s\n",
-                                       n->name, n->ifname, z->name, n->name, n->ifname,
-                                       f->dest->name, n2->name, n2->ifname);
-
                                if( (x = fwd_xt_init_rule(h_filter)) != NULL )
                                {
                                        fwd_xt_parse_in(x, n, 0);                               /* -i ... */
@@ -746,9 +726,6 @@ void fwd_ipt_addif(struct fwd_handle *h, const char *net)
                /* No destination specified, treat it as input rule */
                else
                {
-                       printf("\n# Net %s (%s) - rule Z:%s N:%s I:%s\n",
-                               n->name, n->ifname, z->name, n->name, n->ifname);
-
                        if( (x = fwd_xt_init_rule(h_filter)) != NULL )
                        {
                                fwd_xt_parse_in(x, n, 0);                               /* -i ... */
@@ -835,7 +812,7 @@ void fwd_ipt_delif(struct fwd_handle *h, const char *net)
                fwd_fatal("Unable to obtain libiptc handle");
 
 
-       printf("\n\n#\n# delif(%s)\n#\n", net);
+       fwd_log_info("Removing network %s", net);
 
        /* delete network related rules */
        fwd_ipt_delif_table(h_nat, net);