Blame extensions/libxt_time.c

Packit Service d1fe03
/*
Packit Service d1fe03
 *	libxt_time - iptables part for xt_time
Packit Service d1fe03
 *	Copyright © CC Computer Consultants GmbH, 2007
Packit Service d1fe03
 *	Contact: <jengelh@computergmbh.de>
Packit Service d1fe03
 *
Packit Service d1fe03
 *	libxt_time.c is free software; you can redistribute it and/or modify
Packit Service d1fe03
 *	it under the terms of the GNU General Public License as published by
Packit Service d1fe03
 *	the Free Software Foundation; either version 2 or 3 of the License.
Packit Service d1fe03
 *
Packit Service d1fe03
 *	Based on libipt_time.c.
Packit Service d1fe03
 */
Packit Service d1fe03
#include <stdio.h>
Packit Service d1fe03
#include <string.h>
Packit Service d1fe03
#include <stdlib.h>
Packit Service d1fe03
#include <time.h>
Packit Service d1fe03
#include <linux/types.h>
Packit Service d1fe03
#include <linux/netfilter/xt_time.h>
Packit Service d1fe03
#include <xtables.h>
Packit Service d1fe03
Packit Service d1fe03
enum {
Packit Service d1fe03
	O_DATE_START = 0,
Packit Service d1fe03
	O_DATE_STOP,
Packit Service d1fe03
	O_TIME_START,
Packit Service d1fe03
	O_TIME_STOP,
Packit Service d1fe03
	O_TIME_CONTIGUOUS,
Packit Service d1fe03
	O_MONTHDAYS,
Packit Service d1fe03
	O_WEEKDAYS,
Packit Service d1fe03
	O_LOCAL_TZ,
Packit Service d1fe03
	O_UTC,
Packit Service d1fe03
	O_KERNEL_TZ,
Packit Service d1fe03
	F_LOCAL_TZ  = 1 << O_LOCAL_TZ,
Packit Service d1fe03
	F_UTC       = 1 << O_UTC,
Packit Service d1fe03
	F_KERNEL_TZ = 1 << O_KERNEL_TZ,
Packit Service d1fe03
	F_TIME_CONTIGUOUS = 1 << O_TIME_CONTIGUOUS,
Packit Service d1fe03
};
Packit Service d1fe03
Packit Service d1fe03
static const char *const week_days[] = {
Packit Service d1fe03
	NULL, "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
Packit Service d1fe03
};
Packit Service d1fe03
Packit Service d1fe03
static const struct xt_option_entry time_opts[] = {
Packit Service d1fe03
	{.name = "datestart", .id = O_DATE_START, .type = XTTYPE_STRING},
Packit Service d1fe03
	{.name = "datestop", .id = O_DATE_STOP, .type = XTTYPE_STRING},
Packit Service d1fe03
	{.name = "timestart", .id = O_TIME_START, .type = XTTYPE_STRING},
Packit Service d1fe03
	{.name = "timestop", .id = O_TIME_STOP, .type = XTTYPE_STRING},
Packit Service d1fe03
	{.name = "contiguous", .id = O_TIME_CONTIGUOUS, .type = XTTYPE_NONE},
Packit Service d1fe03
	{.name = "weekdays", .id = O_WEEKDAYS, .type = XTTYPE_STRING,
Packit Service d1fe03
	 .flags = XTOPT_INVERT},
Packit Service d1fe03
	{.name = "monthdays", .id = O_MONTHDAYS, .type = XTTYPE_STRING,
Packit Service d1fe03
	 .flags = XTOPT_INVERT},
Packit Service d1fe03
	{.name = "localtz", .id = O_LOCAL_TZ, .type = XTTYPE_NONE,
Packit Service d1fe03
	 .excl = F_UTC},
Packit Service d1fe03
	{.name = "utc", .id = O_UTC, .type = XTTYPE_NONE,
Packit Service d1fe03
	 .excl = F_LOCAL_TZ | F_KERNEL_TZ},
Packit Service d1fe03
	{.name = "kerneltz", .id = O_KERNEL_TZ, .type = XTTYPE_NONE,
Packit Service d1fe03
	 .excl = F_UTC},
Packit Service d1fe03
	XTOPT_TABLEEND,
Packit Service d1fe03
};
Packit Service d1fe03
Packit Service d1fe03
static void time_help(void)
Packit Service d1fe03
{
Packit Service d1fe03
	printf(
Packit Service d1fe03
"time match options:\n"
Packit Service d1fe03
"    --datestart time     Start and stop time, to be given in ISO 8601\n"
Packit Service d1fe03
"    --datestop time      (YYYY[-MM[-DD[Thh[:mm[:ss]]]]])\n"
Packit Service d1fe03
"    --timestart time     Start and stop daytime (hh:mm[:ss])\n"
Packit Service d1fe03
"    --timestop time      (between 00:00:00 and 23:59:59)\n"
Packit Service d1fe03
"[!] --monthdays value    List of days on which to match, separated by comma\n"
Packit Service d1fe03
"                         (Possible days: 1 to 31; defaults to all)\n"
Packit Service d1fe03
"[!] --weekdays value     List of weekdays on which to match, sep. by comma\n"
Packit Service d1fe03
"                         (Possible days: Mon,Tue,Wed,Thu,Fri,Sat,Sun or 1 to 7\n"
Packit Service d1fe03
"                         Defaults to all weekdays.)\n"
Packit Service d1fe03
"    --kerneltz           Work with the kernel timezone instead of UTC\n");
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static void time_init(struct xt_entry_match *m)
Packit Service d1fe03
{
Packit Service d1fe03
	struct xt_time_info *info = (void *)m->data;
Packit Service d1fe03
Packit Service d1fe03
	/* By default, we match on every day, every daytime */
Packit Service d1fe03
	info->monthdays_match = XT_TIME_ALL_MONTHDAYS;
Packit Service d1fe03
	info->weekdays_match  = XT_TIME_ALL_WEEKDAYS;
Packit Service d1fe03
	info->daytime_start   = XT_TIME_MIN_DAYTIME;
Packit Service d1fe03
	info->daytime_stop    = XT_TIME_MAX_DAYTIME;
Packit Service d1fe03
Packit Service d1fe03
	/* ...and have no date-begin or date-end boundary */
Packit Service d1fe03
	info->date_start = 0;
Packit Service d1fe03
	info->date_stop  = INT_MAX;
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static time_t time_parse_date(const char *s)
Packit Service d1fe03
{
Packit Service d1fe03
	unsigned int month = 1, day = 1, hour = 0, minute = 0, second = 0;
Packit Service d1fe03
	unsigned int year;
Packit Service d1fe03
	const char *os = s;
Packit Service d1fe03
	struct tm tm;
Packit Service d1fe03
	time_t ret;
Packit Service d1fe03
	char *e;
Packit Service d1fe03
Packit Service d1fe03
	year = strtoul(s, &e, 10);
Packit Service d1fe03
	if ((*e != '-' && *e != '\0') || year < 1970 || year > 2038)
Packit Service d1fe03
		goto out;
Packit Service d1fe03
	if (*e == '\0')
Packit Service d1fe03
		goto eval;
Packit Service d1fe03
Packit Service d1fe03
	s = e + 1;
Packit Service d1fe03
	month = strtoul(s, &e, 10);
Packit Service d1fe03
	if ((*e != '-' && *e != '\0') || month > 12)
Packit Service d1fe03
		goto out;
Packit Service d1fe03
	if (*e == '\0')
Packit Service d1fe03
		goto eval;
Packit Service d1fe03
Packit Service d1fe03
	s = e + 1;
Packit Service d1fe03
	day = strtoul(s, &e, 10);
Packit Service d1fe03
	if ((*e != 'T' && *e != '\0') || day > 31)
Packit Service d1fe03
		goto out;
Packit Service d1fe03
	if (*e == '\0')
Packit Service d1fe03
		goto eval;
Packit Service d1fe03
Packit Service d1fe03
	s = e + 1;
Packit Service d1fe03
	hour = strtoul(s, &e, 10);
Packit Service d1fe03
	if ((*e != ':' && *e != '\0') || hour > 23)
Packit Service d1fe03
		goto out;
Packit Service d1fe03
	if (*e == '\0')
Packit Service d1fe03
		goto eval;
Packit Service d1fe03
Packit Service d1fe03
	s = e + 1;
Packit Service d1fe03
	minute = strtoul(s, &e, 10);
Packit Service d1fe03
	if ((*e != ':' && *e != '\0') || minute > 59)
Packit Service d1fe03
		goto out;
Packit Service d1fe03
	if (*e == '\0')
Packit Service d1fe03
		goto eval;
Packit Service d1fe03
Packit Service d1fe03
	s = e + 1;
Packit Service d1fe03
	second = strtoul(s, &e, 10);
Packit Service d1fe03
	if (*e != '\0' || second > 59)
Packit Service d1fe03
		goto out;
Packit Service d1fe03
Packit Service d1fe03
 eval:
Packit Service d1fe03
	tm.tm_year = year - 1900;
Packit Service d1fe03
	tm.tm_mon  = month - 1;
Packit Service d1fe03
	tm.tm_mday = day;
Packit Service d1fe03
	tm.tm_hour = hour;
Packit Service d1fe03
	tm.tm_min  = minute;
Packit Service d1fe03
	tm.tm_sec  = second;
Packit Service d1fe03
	tm.tm_isdst = 0;
Packit Service d1fe03
	/*
Packit Service d1fe03
	 * Offsetting, if any, is done by xt_time.ko,
Packit Service d1fe03
	 * so we have to disable it here in userspace.
Packit Service d1fe03
	 */
Packit Service d1fe03
	setenv("TZ", "UTC", true);
Packit Service d1fe03
	tzset();
Packit Service d1fe03
	ret = mktime(&tm;;
Packit Service d1fe03
	if (ret >= 0)
Packit Service d1fe03
		return ret;
Packit Service d1fe03
	perror("mktime");
Packit Service d1fe03
	xtables_error(OTHER_PROBLEM, "mktime returned an error");
Packit Service d1fe03
Packit Service d1fe03
 out:
Packit Service d1fe03
	xtables_error(PARAMETER_PROBLEM, "Invalid date \"%s\" specified. Should "
Packit Service d1fe03
	           "be YYYY[-MM[-DD[Thh[:mm[:ss]]]]]", os);
Packit Service d1fe03
	return -1;
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static unsigned int time_parse_minutes(const char *s)
Packit Service d1fe03
{
Packit Service d1fe03
	unsigned int hour, minute, second = 0;
Packit Service d1fe03
	char *e;
Packit Service d1fe03
Packit Service d1fe03
	hour = strtoul(s, &e, 10);
Packit Service d1fe03
	if (*e != ':' || hour > 23)
Packit Service d1fe03
		goto out;
Packit Service d1fe03
Packit Service d1fe03
	s = e + 1;
Packit Service d1fe03
	minute = strtoul(s, &e, 10);
Packit Service d1fe03
	if ((*e != ':' && *e != '\0') || minute > 59)
Packit Service d1fe03
		goto out;
Packit Service d1fe03
	if (*e == '\0')
Packit Service d1fe03
		goto eval;
Packit Service d1fe03
Packit Service d1fe03
	s = e + 1;
Packit Service d1fe03
	second = strtoul(s, &e, 10);
Packit Service d1fe03
	if (*e != '\0' || second > 59)
Packit Service d1fe03
		goto out;
Packit Service d1fe03
Packit Service d1fe03
 eval:
Packit Service d1fe03
	return 60 * 60 * hour + 60 * minute + second;
Packit Service d1fe03
Packit Service d1fe03
 out:
Packit Service d1fe03
	xtables_error(PARAMETER_PROBLEM, "invalid time \"%s\" specified, "
Packit Service d1fe03
	           "should be hh:mm[:ss] format and within the boundaries", s);
Packit Service d1fe03
	return -1;
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static const char *my_strseg(char *buf, unsigned int buflen,
Packit Service d1fe03
    const char **arg, char delim)
Packit Service d1fe03
{
Packit Service d1fe03
	const char *sep;
Packit Service d1fe03
Packit Service d1fe03
	if (*arg == NULL || **arg == '\0')
Packit Service d1fe03
		return NULL;
Packit Service d1fe03
	sep = strchr(*arg, delim);
Packit Service d1fe03
	if (sep == NULL) {
Packit Service d1fe03
		snprintf(buf, buflen, "%s", *arg);
Packit Service d1fe03
		*arg = NULL;
Packit Service d1fe03
		return buf;
Packit Service d1fe03
	}
Packit Service d1fe03
	snprintf(buf, buflen, "%.*s", (unsigned int)(sep - *arg), *arg);
Packit Service d1fe03
	*arg = sep + 1;
Packit Service d1fe03
	return buf;
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static uint32_t time_parse_monthdays(const char *arg)
Packit Service d1fe03
{
Packit Service d1fe03
	char day[3], *err = NULL;
Packit Service d1fe03
	uint32_t ret = 0;
Packit Service d1fe03
	unsigned int i;
Packit Service d1fe03
Packit Service d1fe03
	while (my_strseg(day, sizeof(day), &arg, ',') != NULL) {
Packit Service d1fe03
		i = strtoul(day, &err, 0);
Packit Service d1fe03
		if ((*err != ',' && *err != '\0') || i > 31)
Packit Service d1fe03
			xtables_error(PARAMETER_PROBLEM,
Packit Service d1fe03
			           "%s is not a valid day for --monthdays", day);
Packit Service d1fe03
		ret |= 1 << i;
Packit Service d1fe03
	}
Packit Service d1fe03
Packit Service d1fe03
	return ret;
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static unsigned int time_parse_weekdays(const char *arg)
Packit Service d1fe03
{
Packit Service d1fe03
	char day[4], *err = NULL;
Packit Service d1fe03
	unsigned int i, ret = 0;
Packit Service d1fe03
	bool valid;
Packit Service d1fe03
Packit Service d1fe03
	while (my_strseg(day, sizeof(day), &arg, ',') != NULL) {
Packit Service d1fe03
		i = strtoul(day, &err, 0);
Packit Service d1fe03
		if (*err == '\0') {
Packit Service d1fe03
			if (i == 0)
Packit Service d1fe03
				xtables_error(PARAMETER_PROBLEM,
Packit Service d1fe03
				           "No, the week does NOT begin with Sunday.");
Packit Service d1fe03
			ret |= 1 << i;
Packit Service d1fe03
			continue;
Packit Service d1fe03
		}
Packit Service d1fe03
Packit Service d1fe03
		valid = false;
Packit Service d1fe03
		for (i = 1; i < ARRAY_SIZE(week_days); ++i)
Packit Service d1fe03
			if (strncmp(day, week_days[i], 2) == 0) {
Packit Service d1fe03
				ret |= 1 << i;
Packit Service d1fe03
				valid = true;
Packit Service d1fe03
			}
Packit Service d1fe03
Packit Service d1fe03
		if (!valid)
Packit Service d1fe03
			xtables_error(PARAMETER_PROBLEM,
Packit Service d1fe03
			           "%s is not a valid day specifier", day);
Packit Service d1fe03
	}
Packit Service d1fe03
Packit Service d1fe03
	return ret;
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static void time_parse(struct xt_option_call *cb)
Packit Service d1fe03
{
Packit Service d1fe03
	struct xt_time_info *info = cb->data;
Packit Service d1fe03
Packit Service d1fe03
	xtables_option_parse(cb);
Packit Service d1fe03
	switch (cb->entry->id) {
Packit Service d1fe03
	case O_DATE_START:
Packit Service d1fe03
		info->date_start = time_parse_date(cb->arg);
Packit Service d1fe03
		break;
Packit Service d1fe03
	case O_DATE_STOP:
Packit Service d1fe03
		info->date_stop = time_parse_date(cb->arg);
Packit Service d1fe03
		break;
Packit Service d1fe03
	case O_TIME_START:
Packit Service d1fe03
		info->daytime_start = time_parse_minutes(cb->arg);
Packit Service d1fe03
		break;
Packit Service d1fe03
	case O_TIME_STOP:
Packit Service d1fe03
		info->daytime_stop = time_parse_minutes(cb->arg);
Packit Service d1fe03
		break;
Packit Service d1fe03
	case O_TIME_CONTIGUOUS:
Packit Service d1fe03
		info->flags |= XT_TIME_CONTIGUOUS;
Packit Service d1fe03
		break;
Packit Service d1fe03
	case O_LOCAL_TZ:
Packit Service d1fe03
		fprintf(stderr, "WARNING: --localtz is being replaced by "
Packit Service d1fe03
		        "--kerneltz, since \"local\" is ambiguous. Note the "
Packit Service d1fe03
		        "kernel timezone has caveats - "
Packit Service d1fe03
		        "see manpage for details.\n");
Packit Service d1fe03
		/* fallthrough */
Packit Service d1fe03
	case O_KERNEL_TZ:
Packit Service d1fe03
		info->flags |= XT_TIME_LOCAL_TZ;
Packit Service d1fe03
		break;
Packit Service d1fe03
	case O_MONTHDAYS:
Packit Service d1fe03
		info->monthdays_match = time_parse_monthdays(cb->arg);
Packit Service d1fe03
		if (cb->invert)
Packit Service d1fe03
			info->monthdays_match ^= XT_TIME_ALL_MONTHDAYS;
Packit Service d1fe03
		break;
Packit Service d1fe03
	case O_WEEKDAYS:
Packit Service d1fe03
		info->weekdays_match = time_parse_weekdays(cb->arg);
Packit Service d1fe03
		if (cb->invert)
Packit Service d1fe03
			info->weekdays_match ^= XT_TIME_ALL_WEEKDAYS;
Packit Service d1fe03
		break;
Packit Service d1fe03
	}
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static void time_print_date(time_t date, const char *command)
Packit Service d1fe03
{
Packit Service d1fe03
	struct tm *t;
Packit Service d1fe03
Packit Service d1fe03
	/* If it is the default value, do not print it. */
Packit Service d1fe03
	if (date == 0 || date == LONG_MAX)
Packit Service d1fe03
		return;
Packit Service d1fe03
Packit Service d1fe03
	t = gmtime(&date);
Packit Service d1fe03
	if (command != NULL)
Packit Service d1fe03
		/*
Packit Service d1fe03
		 * Need a contiguous string (no whitespaces), hence using
Packit Service d1fe03
		 * the ISO 8601 "T" variant.
Packit Service d1fe03
		 */
Packit Service d1fe03
		printf(" %s %04u-%02u-%02uT%02u:%02u:%02u",
Packit Service d1fe03
		       command, t->tm_year + 1900, t->tm_mon + 1,
Packit Service d1fe03
		       t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
Packit Service d1fe03
	else
Packit Service d1fe03
		printf(" %04u-%02u-%02u %02u:%02u:%02u",
Packit Service d1fe03
		       t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
Packit Service d1fe03
		       t->tm_hour, t->tm_min, t->tm_sec);
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static void time_print_monthdays(uint32_t mask, bool human_readable)
Packit Service d1fe03
{
Packit Service d1fe03
	unsigned int i, nbdays = 0;
Packit Service d1fe03
Packit Service d1fe03
	printf(" ");
Packit Service d1fe03
	for (i = 1; i <= 31; ++i)
Packit Service d1fe03
		if (mask & (1 << i)) {
Packit Service d1fe03
			if (nbdays++ > 0)
Packit Service d1fe03
				printf(",");
Packit Service d1fe03
			printf("%u", i);
Packit Service d1fe03
			if (human_readable)
Packit Service d1fe03
				switch (i % 10) {
Packit Service d1fe03
					case 1:
Packit Service d1fe03
						printf("st");
Packit Service d1fe03
						break;
Packit Service d1fe03
					case 2:
Packit Service d1fe03
						printf("nd");
Packit Service d1fe03
						break;
Packit Service d1fe03
					case 3:
Packit Service d1fe03
						printf("rd");
Packit Service d1fe03
						break;
Packit Service d1fe03
					default:
Packit Service d1fe03
						printf("th");
Packit Service d1fe03
						break;
Packit Service d1fe03
				}
Packit Service d1fe03
		}
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static void time_print_weekdays(unsigned int mask)
Packit Service d1fe03
{
Packit Service d1fe03
	unsigned int i, nbdays = 0;
Packit Service d1fe03
Packit Service d1fe03
	printf(" ");
Packit Service d1fe03
	for (i = 1; i <= 7; ++i)
Packit Service d1fe03
		if (mask & (1 << i)) {
Packit Service d1fe03
			if (nbdays > 0)
Packit Service d1fe03
				printf(",%s", week_days[i]);
Packit Service d1fe03
			else
Packit Service d1fe03
				printf("%s", week_days[i]);
Packit Service d1fe03
			++nbdays;
Packit Service d1fe03
		}
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static inline void divide_time(unsigned int fulltime, unsigned int *hours,
Packit Service d1fe03
    unsigned int *minutes, unsigned int *seconds)
Packit Service d1fe03
{
Packit Service d1fe03
	*seconds  = fulltime % 60;
Packit Service d1fe03
	fulltime /= 60;
Packit Service d1fe03
	*minutes  = fulltime % 60;
Packit Service d1fe03
	*hours    = fulltime / 60;
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static void time_print(const void *ip, const struct xt_entry_match *match,
Packit Service d1fe03
                       int numeric)
Packit Service d1fe03
{
Packit Service d1fe03
	const struct xt_time_info *info = (const void *)match->data;
Packit Service d1fe03
	unsigned int h, m, s;
Packit Service d1fe03
Packit Service d1fe03
	printf(" TIME");
Packit Service d1fe03
Packit Service d1fe03
	if (info->daytime_start != XT_TIME_MIN_DAYTIME ||
Packit Service d1fe03
	    info->daytime_stop != XT_TIME_MAX_DAYTIME) {
Packit Service d1fe03
		divide_time(info->daytime_start, &h, &m, &s);
Packit Service d1fe03
		printf(" from %02u:%02u:%02u", h, m, s);
Packit Service d1fe03
		divide_time(info->daytime_stop, &h, &m, &s);
Packit Service d1fe03
		printf(" to %02u:%02u:%02u", h, m, s);
Packit Service d1fe03
	}
Packit Service d1fe03
	if (info->weekdays_match != XT_TIME_ALL_WEEKDAYS) {
Packit Service d1fe03
		printf(" on");
Packit Service d1fe03
		time_print_weekdays(info->weekdays_match);
Packit Service d1fe03
	}
Packit Service d1fe03
	if (info->monthdays_match != XT_TIME_ALL_MONTHDAYS) {
Packit Service d1fe03
		printf(" on");
Packit Service d1fe03
		time_print_monthdays(info->monthdays_match, true);
Packit Service d1fe03
	}
Packit Service d1fe03
	if (info->date_start != 0) {
Packit Service d1fe03
		printf(" starting from");
Packit Service d1fe03
		time_print_date(info->date_start, NULL);
Packit Service d1fe03
	}
Packit Service d1fe03
	if (info->date_stop != INT_MAX) {
Packit Service d1fe03
		printf(" until date");
Packit Service d1fe03
		time_print_date(info->date_stop, NULL);
Packit Service d1fe03
	}
Packit Service d1fe03
	if (!(info->flags & XT_TIME_LOCAL_TZ))
Packit Service d1fe03
		printf(" UTC");
Packit Service d1fe03
	if (info->flags & XT_TIME_CONTIGUOUS)
Packit Service d1fe03
		printf(" contiguous");
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static void time_save(const void *ip, const struct xt_entry_match *match)
Packit Service d1fe03
{
Packit Service d1fe03
	const struct xt_time_info *info = (const void *)match->data;
Packit Service d1fe03
	unsigned int h, m, s;
Packit Service d1fe03
Packit Service d1fe03
	if (info->daytime_start != XT_TIME_MIN_DAYTIME ||
Packit Service d1fe03
	    info->daytime_stop != XT_TIME_MAX_DAYTIME) {
Packit Service d1fe03
		divide_time(info->daytime_start, &h, &m, &s);
Packit Service d1fe03
		printf(" --timestart %02u:%02u:%02u", h, m, s);
Packit Service d1fe03
		divide_time(info->daytime_stop, &h, &m, &s);
Packit Service d1fe03
		printf(" --timestop %02u:%02u:%02u", h, m, s);
Packit Service d1fe03
	}
Packit Service d1fe03
	if (info->monthdays_match != XT_TIME_ALL_MONTHDAYS) {
Packit Service d1fe03
		printf(" --monthdays");
Packit Service d1fe03
		time_print_monthdays(info->monthdays_match, false);
Packit Service d1fe03
	}
Packit Service d1fe03
	if (info->weekdays_match != XT_TIME_ALL_WEEKDAYS) {
Packit Service d1fe03
		printf(" --weekdays");
Packit Service d1fe03
		time_print_weekdays(info->weekdays_match);
Packit Service d1fe03
	}
Packit Service d1fe03
	time_print_date(info->date_start, "--datestart");
Packit Service d1fe03
	time_print_date(info->date_stop, "--datestop");
Packit Service d1fe03
	if (info->flags & XT_TIME_LOCAL_TZ)
Packit Service d1fe03
		printf(" --kerneltz");
Packit Service d1fe03
	if (info->flags & XT_TIME_CONTIGUOUS)
Packit Service d1fe03
		printf(" --contiguous");
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static void time_check(struct xt_fcheck_call *cb)
Packit Service d1fe03
{
Packit Service d1fe03
	const struct xt_time_info *info = (const void *) cb->data;
Packit Service d1fe03
	if ((cb->xflags & F_TIME_CONTIGUOUS) &&
Packit Service d1fe03
	     info->daytime_start < info->daytime_stop)
Packit Service d1fe03
		xtables_error(PARAMETER_PROBLEM,
Packit Service d1fe03
			"time: --contiguous only makes sense when stoptime is smaller than starttime");
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static struct xtables_match time_match = {
Packit Service d1fe03
	.name          = "time",
Packit Service d1fe03
	.family        = NFPROTO_UNSPEC,
Packit Service d1fe03
	.version       = XTABLES_VERSION,
Packit Service d1fe03
	.size          = XT_ALIGN(sizeof(struct xt_time_info)),
Packit Service d1fe03
	.userspacesize = XT_ALIGN(sizeof(struct xt_time_info)),
Packit Service d1fe03
	.help          = time_help,
Packit Service d1fe03
	.init          = time_init,
Packit Service d1fe03
	.print         = time_print,
Packit Service d1fe03
	.save          = time_save,
Packit Service d1fe03
	.x6_parse      = time_parse,
Packit Service d1fe03
	.x6_fcheck     = time_check,
Packit Service d1fe03
	.x6_options    = time_opts,
Packit Service d1fe03
};
Packit Service d1fe03
Packit Service d1fe03
void _init(void)
Packit Service d1fe03
{
Packit Service d1fe03
	xtables_register_match(&time_match);
Packit Service d1fe03
}