mirror of
git://git.code.sf.net/p/xtables-addons/xtables-addons
synced 2025-09-06 04:35:12 +02:00
pknock: trim some blank lines
This commit is contained in:
@@ -11,7 +11,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <xtables.h>
|
#include <xtables.h>
|
||||||
#include <linux/netfilter.h>
|
#include <linux/netfilter.h>
|
||||||
#include <linux/netfilter_ipv4/ip_tables.h>
|
#include <linux/netfilter_ipv4/ip_tables.h>
|
||||||
@@ -70,7 +69,6 @@ parse_ports(const char *portstring, uint16_t *ports, const char *proto)
|
|||||||
|
|
||||||
if (cp != NULL)
|
if (cp != NULL)
|
||||||
xtables_error(PARAMETER_PROBLEM, "too many ports specified");
|
xtables_error(PARAMETER_PROBLEM, "too many ports specified");
|
||||||
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@@ -212,7 +210,6 @@ __pknock_parse(int c, char **argv, int invert, unsigned int *flags,
|
|||||||
|
|
||||||
if (invert)
|
if (invert)
|
||||||
xtables_error(PARAMETER_PROBLEM, PKNOCK "does not support invert.");
|
xtables_error(PARAMETER_PROBLEM, PKNOCK "does not support invert.");
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,7 +263,7 @@ static void pknock_mt_check(unsigned int flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void pknock_mt_print(const void *ip,
|
static void pknock_mt_print(const void *ip,
|
||||||
const struct xt_entry_match *match, int numeric)
|
const struct xt_entry_match *match, int numeric)
|
||||||
{
|
{
|
||||||
const struct xt_pknock_mtinfo *info = (void *)match->data;
|
const struct xt_pknock_mtinfo *info = (void *)match->data;
|
||||||
int i;
|
int i;
|
||||||
|
@@ -55,7 +55,6 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sock_fd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR);
|
sock_fd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR);
|
||||||
|
|
||||||
if (sock_fd == -1) {
|
if (sock_fd == -1) {
|
||||||
perror("socket()");
|
perror("socket()");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
@@ -90,21 +90,17 @@ enum {
|
|||||||
#define hashtable_for_each_safe(pos, n, head, size, i) \
|
#define hashtable_for_each_safe(pos, n, head, size, i) \
|
||||||
for ((i) = 0; (i) < (size); ++(i)) \
|
for ((i) = 0; (i) < (size); ++(i)) \
|
||||||
list_for_each_safe((pos), (n), (&head[(i)]))
|
list_for_each_safe((pos), (n), (&head[(i)]))
|
||||||
|
|
||||||
#define pk_debug(msg, peer) pr_debug( \
|
#define pk_debug(msg, peer) pr_debug( \
|
||||||
"(S) peer: " NIPQUAD_FMT " - %s.\n", \
|
"(S) peer: " NIPQUAD_FMT " - %s.\n", \
|
||||||
NIPQUAD((peer)->ip), msg)
|
NIPQUAD((peer)->ip), msg)
|
||||||
|
|
||||||
static uint32_t ipt_pknock_hash_rnd;
|
static uint32_t ipt_pknock_hash_rnd;
|
||||||
|
|
||||||
static unsigned int rule_hashsize = DEFAULT_RULE_HASH_SIZE;
|
static unsigned int rule_hashsize = DEFAULT_RULE_HASH_SIZE;
|
||||||
static unsigned int peer_hashsize = DEFAULT_PEER_HASH_SIZE;
|
static unsigned int peer_hashsize = DEFAULT_PEER_HASH_SIZE;
|
||||||
static unsigned int gc_expir_time = DEFAULT_GC_EXPIRATION_TIME;
|
static unsigned int gc_expir_time = DEFAULT_GC_EXPIRATION_TIME;
|
||||||
static int nl_multicast_group = -1;
|
static int nl_multicast_group = -1;
|
||||||
|
|
||||||
static struct list_head *rule_hashtable;
|
static struct list_head *rule_hashtable;
|
||||||
static struct proc_dir_entry *pde;
|
static struct proc_dir_entry *pde;
|
||||||
|
|
||||||
static DEFINE_SPINLOCK(list_lock);
|
static DEFINE_SPINLOCK(list_lock);
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
@@ -159,7 +155,6 @@ alloc_hashtable(unsigned int size)
|
|||||||
return NULL;
|
return NULL;
|
||||||
for (i = 0; i < size; ++i)
|
for (i = 0; i < size; ++i)
|
||||||
INIT_LIST_HEAD(&hash[i]);
|
INIT_LIST_HEAD(&hash[i]);
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,10 +186,8 @@ pknock_seq_start(struct seq_file *s, loff_t *pos)
|
|||||||
const struct xt_pknock_rule *rule = s->private;
|
const struct xt_pknock_rule *rule = s->private;
|
||||||
|
|
||||||
spin_lock_bh(&list_lock);
|
spin_lock_bh(&list_lock);
|
||||||
|
|
||||||
if (*pos >= peer_hashsize)
|
if (*pos >= peer_hashsize)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return rule->peer_head + *pos;
|
return rule->peer_head + *pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +205,6 @@ pknock_seq_next(struct seq_file *s, void *v, loff_t *pos)
|
|||||||
++*pos;
|
++*pos;
|
||||||
if (*pos >= peer_hashsize)
|
if (*pos >= peer_hashsize)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return rule->peer_head + *pos;
|
return rule->peer_head + *pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,7 +230,6 @@ pknock_seq_show(struct seq_file *s, void *v)
|
|||||||
const struct peer *peer;
|
const struct peer *peer;
|
||||||
unsigned long time;
|
unsigned long time;
|
||||||
const struct list_head *peer_head = v;
|
const struct list_head *peer_head = v;
|
||||||
|
|
||||||
const struct xt_pknock_rule *rule = s->private;
|
const struct xt_pknock_rule *rule = s->private;
|
||||||
|
|
||||||
list_for_each_safe(pos, n, peer_head) {
|
list_for_each_safe(pos, n, peer_head) {
|
||||||
@@ -311,7 +302,6 @@ static void update_rule_gc_timer(struct xt_pknock_rule *rule)
|
|||||||
{
|
{
|
||||||
if (timer_pending(&rule->timer))
|
if (timer_pending(&rule->timer))
|
||||||
del_timer(&rule->timer);
|
del_timer(&rule->timer);
|
||||||
|
|
||||||
rule->timer.expires = jiffies + msecs_to_jiffies(gc_expir_time);
|
rule->timer.expires = jiffies + msecs_to_jiffies(gc_expir_time);
|
||||||
add_timer(&rule->timer);
|
add_timer(&rule->timer);
|
||||||
}
|
}
|
||||||
@@ -433,7 +423,6 @@ add_rule(struct xt_pknock_mtinfo *info)
|
|||||||
|
|
||||||
list_for_each_safe(pos, n, &rule_hashtable[hash]) {
|
list_for_each_safe(pos, n, &rule_hashtable[hash]) {
|
||||||
rule = list_entry(pos, struct xt_pknock_rule, head);
|
rule = list_entry(pos, struct xt_pknock_rule, head);
|
||||||
|
|
||||||
if (!rulecmp(info, rule))
|
if (!rulecmp(info, rule))
|
||||||
continue;
|
continue;
|
||||||
++rule->ref_count;
|
++rule->ref_count;
|
||||||
@@ -442,7 +431,6 @@ add_rule(struct xt_pknock_mtinfo *info)
|
|||||||
rule->max_time = info->max_time;
|
rule->max_time = info->max_time;
|
||||||
rule->autoclose_time = info->autoclose_time;
|
rule->autoclose_time = info->autoclose_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->option & XT_PKNOCK_CHECKIP)
|
if (info->option & XT_PKNOCK_CHECKIP)
|
||||||
pr_debug("add_rule() (AC) rule found: %s - "
|
pr_debug("add_rule() (AC) rule found: %s - "
|
||||||
"ref_count: %d\n",
|
"ref_count: %d\n",
|
||||||
@@ -457,7 +445,6 @@ add_rule(struct xt_pknock_mtinfo *info)
|
|||||||
INIT_LIST_HEAD(&rule->head);
|
INIT_LIST_HEAD(&rule->head);
|
||||||
strncpy(rule->rule_name, info->rule_name, info->rule_name_len);
|
strncpy(rule->rule_name, info->rule_name, info->rule_name_len);
|
||||||
rule->rule_name_len = info->rule_name_len;
|
rule->rule_name_len = info->rule_name_len;
|
||||||
|
|
||||||
rule->ref_count = 1;
|
rule->ref_count = 1;
|
||||||
rule->max_time = info->max_time;
|
rule->max_time = info->max_time;
|
||||||
rule->autoclose_time = info->autoclose_time;
|
rule->autoclose_time = info->autoclose_time;
|
||||||
@@ -500,7 +487,6 @@ remove_rule(struct xt_pknock_mtinfo *info)
|
|||||||
|
|
||||||
list_for_each_safe(pos, n, &rule_hashtable[hash]) {
|
list_for_each_safe(pos, n, &rule_hashtable[hash]) {
|
||||||
rule = list_entry(pos, struct xt_pknock_rule, head);
|
rule = list_entry(pos, struct xt_pknock_rule, head);
|
||||||
|
|
||||||
if (rulecmp(info, rule)) {
|
if (rulecmp(info, rule)) {
|
||||||
found = 1;
|
found = 1;
|
||||||
rule->ref_count--;
|
rule->ref_count--;
|
||||||
@@ -526,7 +512,6 @@ remove_rule(struct xt_pknock_mtinfo *info)
|
|||||||
pr_debug("(D) rule deleted: %s.\n", rule->rule_name);
|
pr_debug("(D) rule deleted: %s.\n", rule->rule_name);
|
||||||
if (timer_pending(&rule->timer))
|
if (timer_pending(&rule->timer))
|
||||||
del_timer(&rule->timer);
|
del_timer(&rule->timer);
|
||||||
|
|
||||||
list_del(&rule->head);
|
list_del(&rule->head);
|
||||||
kfree(rule->peer_head);
|
kfree(rule->peer_head);
|
||||||
kfree(rule);
|
kfree(rule);
|
||||||
@@ -546,7 +531,6 @@ static struct peer *get_peer(struct xt_pknock_rule *rule, __be32 ip)
|
|||||||
unsigned int hash;
|
unsigned int hash;
|
||||||
|
|
||||||
hash = pknock_hash(&ip, sizeof(ip), ipt_pknock_hash_rnd, peer_hashsize);
|
hash = pknock_hash(&ip, sizeof(ip), ipt_pknock_hash_rnd, peer_hashsize);
|
||||||
|
|
||||||
list_for_each_safe(pos, n, &rule->peer_head[hash]) {
|
list_for_each_safe(pos, n, &rule->peer_head[hash]) {
|
||||||
peer = list_entry(pos, struct peer, head);
|
peer = list_entry(pos, struct peer, head);
|
||||||
if (peer->ip == ip)
|
if (peer->ip == ip)
|
||||||
@@ -580,14 +564,12 @@ static struct peer *new_peer(__be32 ip, uint8_t proto)
|
|||||||
|
|
||||||
if (peer == NULL)
|
if (peer == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
INIT_LIST_HEAD(&peer->head);
|
INIT_LIST_HEAD(&peer->head);
|
||||||
peer->ip = ip;
|
peer->ip = ip;
|
||||||
peer->proto = proto;
|
peer->proto = proto;
|
||||||
peer->timestamp = jiffies/HZ;
|
peer->timestamp = jiffies/HZ;
|
||||||
peer->login_sec = 0;
|
peer->login_sec = 0;
|
||||||
reset_knock_status(peer);
|
reset_knock_status(peer);
|
||||||
|
|
||||||
return peer;
|
return peer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -686,7 +668,6 @@ msg_to_userspace_nl(const struct xt_pknock_mtinfo *info,
|
|||||||
|
|
||||||
msg.peer_ip = peer->ip;
|
msg.peer_ip = peer->ip;
|
||||||
scnprintf(msg.rule_name, info->rule_name_len + 1, info->rule_name);
|
scnprintf(msg.rule_name, info->rule_name_len + 1, info->rule_name);
|
||||||
|
|
||||||
memcpy(m + 1, &msg, m->len);
|
memcpy(m + 1, &msg, m->len);
|
||||||
cn_netlink_send(m, 0, multicast_group, GFP_ATOMIC);
|
cn_netlink_send(m, 0, multicast_group, GFP_ATOMIC);
|
||||||
kfree(m);
|
kfree(m);
|
||||||
@@ -768,14 +749,11 @@ has_secret(const unsigned char *secret, unsigned int secret_len, uint32_t ipsrc,
|
|||||||
printk("crypto_shash_update/final() failed ret=%d\n", ret);
|
printk("crypto_shash_update/final() failed ret=%d\n", ret);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
crypt_to_hex(hexresult, result, crypto.size);
|
crypt_to_hex(hexresult, result, crypto.size);
|
||||||
|
|
||||||
if (memcmp(hexresult, payload, hexa_size) != 0)
|
if (memcmp(hexresult, payload, hexa_size) != 0)
|
||||||
pr_debug("secret match failed\n");
|
pr_debug("secret match failed\n");
|
||||||
else
|
else
|
||||||
fret = true;
|
fret = true;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
kfree(hexresult);
|
kfree(hexresult);
|
||||||
return fret;
|
return fret;
|
||||||
@@ -807,7 +785,6 @@ pass_security(struct peer *peer, const struct xt_pknock_mtinfo *info,
|
|||||||
info->open_secret_len, peer->ip,
|
info->open_secret_len, peer->ip,
|
||||||
payload, payload_len))
|
payload, payload_len))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -834,7 +811,6 @@ update_peer(struct peer *peer, const struct xt_pknock_mtinfo *info,
|
|||||||
/* Peer must start the sequence from scratch. */
|
/* Peer must start the sequence from scratch. */
|
||||||
if (info->option & XT_PKNOCK_STRICT)
|
if (info->option & XT_PKNOCK_STRICT)
|
||||||
remove_peer(peer);
|
remove_peer(peer);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -842,25 +818,20 @@ update_peer(struct peer *peer, const struct xt_pknock_mtinfo *info,
|
|||||||
if (info->option & XT_PKNOCK_OPENSECRET ) {
|
if (info->option & XT_PKNOCK_OPENSECRET ) {
|
||||||
if (hdr->proto != IPPROTO_UDP && hdr->proto != IPPROTO_UDPLITE)
|
if (hdr->proto != IPPROTO_UDP && hdr->proto != IPPROTO_UDPLITE)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!pass_security(peer, info, hdr->payload, hdr->payload_len))
|
if (!pass_security(peer, info, hdr->payload, hdr->payload_len))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update the gc timer when there is a state change. */
|
/* Update the gc timer when there is a state change. */
|
||||||
update_rule_gc_timer(rule);
|
update_rule_gc_timer(rule);
|
||||||
|
|
||||||
++peer->accepted_knock_count;
|
++peer->accepted_knock_count;
|
||||||
|
|
||||||
if (is_last_knock(peer, info)) {
|
if (is_last_knock(peer, info)) {
|
||||||
peer->status = ST_ALLOWED;
|
peer->status = ST_ALLOWED;
|
||||||
|
|
||||||
pk_debug("ALLOWED", peer);
|
pk_debug("ALLOWED", peer);
|
||||||
peer->login_sec = get_seconds();
|
peer->login_sec = get_seconds();
|
||||||
|
|
||||||
if (nl_multicast_group > 0)
|
if (nl_multicast_group > 0)
|
||||||
msg_to_userspace_nl(info, peer, nl_multicast_group);
|
msg_to_userspace_nl(info, peer, nl_multicast_group);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -937,7 +908,6 @@ static bool pknock_mt(const struct sk_buff *skb,
|
|||||||
switch (hdr.proto) {
|
switch (hdr.proto) {
|
||||||
case IPPROTO_TCP:
|
case IPPROTO_TCP:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IPPROTO_UDP:
|
case IPPROTO_UDP:
|
||||||
case IPPROTO_UDPLITE:
|
case IPPROTO_UDPLITE:
|
||||||
hdr_len = (iph->ihl * 4) + sizeof(struct udphdr);
|
hdr_len = (iph->ihl * 4) + sizeof(struct udphdr);
|
||||||
@@ -959,12 +929,10 @@ static bool pknock_mt(const struct sk_buff *skb,
|
|||||||
|
|
||||||
/* Gives the peer matching status added to rule depending on ip src. */
|
/* Gives the peer matching status added to rule depending on ip src. */
|
||||||
peer = get_peer(rule, iph->saddr);
|
peer = get_peer(rule, iph->saddr);
|
||||||
|
|
||||||
if (info->option & XT_PKNOCK_CHECKIP) {
|
if (info->option & XT_PKNOCK_CHECKIP) {
|
||||||
ret = is_allowed(peer);
|
ret = is_allowed(peer);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iph->protocol == IPPROTO_UDP || iph->protocol == IPPROTO_UDPLITE) {
|
if (iph->protocol == IPPROTO_UDP || iph->protocol == IPPROTO_UDPLITE) {
|
||||||
hdr.payload = (void *)iph + hdr_len;
|
hdr.payload = (void *)iph + hdr_len;
|
||||||
hdr.payload_len = skb->len - hdr_len;
|
hdr.payload_len = skb->len - hdr_len;
|
||||||
@@ -991,10 +959,8 @@ static bool pknock_mt(const struct sk_buff *skb,
|
|||||||
peer = new_peer(iph->saddr, iph->protocol);
|
peer = new_peer(iph->saddr, iph->protocol);
|
||||||
add_peer(peer, rule);
|
add_peer(peer, rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (peer == NULL)
|
if (peer == NULL)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
update_peer(peer, info, rule, &hdr);
|
update_peer(peer, info, rule, &hdr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1064,11 +1030,9 @@ static int pknock_mt_check(const struct xt_mtchk_param *par)
|
|||||||
memcmp(info->open_secret, info->close_secret,
|
memcmp(info->open_secret, info->close_secret,
|
||||||
info->open_secret_len) == 0)
|
info->open_secret_len) == 0)
|
||||||
RETURN_ERR("opensecret & closesecret cannot be equal.\n");
|
RETURN_ERR("opensecret & closesecret cannot be equal.\n");
|
||||||
|
|
||||||
if (!add_rule(info))
|
if (!add_rule(info))
|
||||||
/* should ENOMEM here */
|
/* should ENOMEM here */
|
||||||
RETURN_ERR("add_rule() error in checkentry() function.\n");
|
RETURN_ERR("add_rule() error in checkentry() function.\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user