Li'l time match userspace patch o' mine
This makes --days optional; if user gives only; if user gives only --timestart and --timestop the rule will be recorded as if all weekdays were specified (intuitive IMHO).
You'll see I accomplished this in a rather ugly fashion (taking advantage of the fact there are options that remain mandatory). I'm sure there is a better way, but this works and the ugliness is totally limited to userspace. Is this acceptable?
libipt_time.c renamed from libipt_time.c.prejuan +20 -6
@@ -17,10 +17,11 @@ {printf ("TIME v%s options:\n" -" --timestart value --timestop value --days listofdays\n" -" timestart value : HH:MM\n" -" timestop value : HH:MM\n" -" listofdays value: a list of days to apply -> ie. Mon,Tue,Wed,Thu,Fri. Case sensitive\n" , +" --timestart value --timestop value [ --days listofdays ]\n" +" timestart value : HH:MM\n" +" timestop value : HH:MM\n" +" listofdays value : a list of days to apply\n" +" -> ie. Mon,Tue,Wed,Thu,Fri. Case sensitive\n" ,IPTABLES_VERSION ); }
@@ -173,6 +174,7 @@unsigned int *nfcache, struct ipt_entry_match **match) { + static int setdaysalready = 0; /* major cheat! */struct ipt_time_info *timeinfo = (struct ipt_time_info *)(*match)->data;int hours, minutes;
@@ -180,6 +182,11 @@ {/* timestart */ case '1' : +if (!setdaysalready) + { + globaldays =127 ;/* All of them if not given */ + timeinfo->days_match = globaldays; + }if (invert)exit_error (PARAMETER_PROBLEM ,"unexpected '!' with --timestart" );
@@ -192,6 +199,11 @@break ;/* timestop */ case '2' : +if (!setdaysalready) + { + globaldays =127 ;/* All of them if not given */ + timeinfo->days_match = globaldays; + }if (invert)exit_error (PARAMETER_PROBLEM ,"unexpected '!' with --timestop" );
@@ -205,6 +217,7 @@/* days */ case '3' : + setdaysalready =1 ;if (invert)exit_error (PARAMETER_PROBLEM ,"unexpected '!' with --days" );
@@ -225,9 +238,10 @@static void final_check (unsigned int flags) { -if (flags != (IPT_TIME_START |IPT_TIME_STOP |IPT_TIME_DAYS )) +if (flags != (IPT_TIME_START |IPT_TIME_STOP |IPT_TIME_DAYS ) && + flags != (IPT_TIME_START |IPT_TIME_STOP ))exit_error (PARAMETER_PROBLEM , -"TIME match: You must specify `--timestart --timestop and --days'" ); +"TIME match: You must specify `--timestart and --timestop'" ); }