コード例 #1
0
/**
 * @s
 * @v
 * @return: 0 if OK
 */
static int
pknock_seq_show(struct seq_file *s, void *v)
{
	struct list_head *pos = NULL, *n = NULL;
	struct peer *peer = NULL;
	unsigned long expir_time = 0;
        u_int32_t ip;

	struct list_head *peer_head = (struct list_head *)v;

	struct proc_dir_entry *pde = s->private;
	struct ipt_pknock_rule *rule = pde->data;

	list_for_each_safe(pos, n, peer_head) {
		peer = list_entry(pos, struct peer, head);
		ip = htonl(peer->ip);
		expir_time = time_before(jiffies/HZ,
						peer->timestamp + rule->max_time)
				? ((peer->timestamp + rule->max_time)-(jiffies/HZ)) : 0;

		seq_printf(s, "src=%u.%u.%u.%u ", NIPQUAD(ip));
		seq_printf(s, "proto=%s ", (peer->proto == IPPROTO_TCP) ?
                                                "TCP" : "UDP");
		seq_printf(s, "status=%s ", status_itoa(peer->status));
		seq_printf(s, "expir_time=%ld ", expir_time);
		seq_printf(s, "next_port_id=%d ", peer->id_port_knocked-1);
		seq_printf(s, "\n");
	}
コード例 #2
0
ファイル: xt_pknock.c プロジェクト: jfenderico/xtables-addons
/**
 * @s
 * @v
 * @return: 0 if OK
 */
static int
pknock_seq_show(struct seq_file *s, void *v)
{
	const struct list_head *pos, *n;
	const struct peer *peer;
	unsigned long time;
	const struct list_head *peer_head = v;

	const struct proc_dir_entry *pde = s->private;
	const struct xt_pknock_rule *rule = pde->data;

	list_for_each_safe(pos, n, peer_head) {
		peer = list_entry(pos, struct peer, head);

		seq_printf(s, "src=" NIPQUAD_FMT " ", NIPQUAD(peer->ip));
		seq_printf(s, "proto=%s ", (peer->proto == IPPROTO_TCP) ?
                                                "TCP" : "UDP");
		seq_printf(s, "status=%s ", status_itoa(peer->status));
		seq_printf(s, "accepted_knock_count=%lu ",
			(unsigned long)peer->accepted_knock_count);
		if (peer->status == ST_MATCHING) {
			time = 0;
			if (time_before(jiffies / HZ, peer->timestamp +
			    rule->max_time))
				time = peer->timestamp + rule->max_time -
				       jiffies / HZ;
			seq_printf(s, "expir_time=%lu [secs] ", time);
		}
		if (peer->status == ST_ALLOWED && rule->autoclose_time != 0) {
			time = 0;
			if (time_before(get_seconds(), peer->login_sec +
			    rule->autoclose_time * 60))
				time = peer->login_sec +
				       rule->autoclose_time * 60 -
				       get_seconds();
			seq_printf(s, "autoclose_time=%lu [secs] ", time);
		}
		seq_printf(s, "\n");
	}