* @rule
* @return: 0 equals, 1 otherwise
*/
-static inline int
+static inline bool
rulecmp(const struct ipt_pknock *info, const struct ipt_pknock_rule *rule)
{
if (info->rule_name_len != rule->rule_name_len)
- return 1;
+ return true;
if (strncmp(info->rule_name, rule->rule_name, info->rule_name_len) != 0)
- return 1;
- return 0;
+ return true;
+ return false;
}
/**
list_for_each_safe(pos, n, &rule_hashtable[hash]) {
rule = list_entry(pos, struct ipt_pknock_rule, head);
- if (rulecmp(info, rule) == 0)
+ if (rulecmp(info, rule))
return rule;
}
return NULL;
list_for_each_safe(pos, n, &rule_hashtable[hash]) {
rule = list_entry(pos, struct ipt_pknock_rule, head);
- if (rulecmp(info, rule) == 0) {
+ if (rulecmp(info, rule)) {
rule->ref_count++;
if (info->option & IPT_PKNOCK_CHECKIP) {
pr_debug("add_rule() (AC)"
list_for_each_safe(pos, n, &rule_hashtable[hash]) {
rule = list_entry(pos, struct ipt_pknock_rule, head);
- if (rulecmp(info, rule) == 0) {
+ if (rulecmp(info, rule)) {
found = 1;
rule->ref_count--;
break;
is_first_knock(const struct peer *peer, const struct ipt_pknock *info,
uint16_t port)
{
- return (peer == NULL && info->port[0] == port) ? 1 : 0;
+ return peer == NULL && info->port[0] == port;
}
/**
* @payload_len
* @return: 1 success, 0 failure
*/
-static int
+static bool
has_secret(const unsigned char *secret, unsigned int secret_len, uint32_t ipsrc,
const unsigned char *payload, unsigned int payload_len)
{
char *hexresult;
unsigned int hexa_size;
int ret;
+ bool fret = false;
unsigned int epoch_min;
if (payload_len == 0)
- return 0;
+ return false;
/*
* hexa: 4bits
/* + 1 cause we MUST add NULL in the payload */
if (payload_len != hexa_size + 1)
- return 0;
+ return false;
hexresult = kmalloc(hexa_size, GFP_ATOMIC);
if (hexresult == NULL) {
printk(KERN_ERR PKNOCK "kmalloc() error in has_secret().\n");
- return 0;
+ return false;
}
memset(result, 0, 64);
ret = crypto_hash_setkey(crypto.tfm, secret, secret_len);
if (ret != 0) {
printk("crypto_hash_setkey() failed ret=%d\n", ret);
- ret = 0;
goto out;
}
ret = crypto_hash_digest(&crypto.desc, sg, 8, result);
if (ret != 0) {
printk("crypto_hash_digest() failed ret=%d\n", ret);
- ret = 0;
goto out;
}
if (memcmp(hexresult, payload, hexa_size) != 0) {
pr_debug("secret match failed\n");
- ret = 0;
+ } else {
+ fret = true;
}
out:
kfree(hexresult);
- return ret;
+ return fret;
}
/**
return ret;
}
-#define RETURN_ERR(err) do { printk(KERN_ERR PKNOCK err); return false; } while (0)
+#define RETURN_ERR(err) do { printk(KERN_ERR PKNOCK err); return false; } while (false)
static bool pknock_mt_check(const struct xt_mtchk_param *par)
{