|
@@ -54,18 +54,21 @@ ctnetlink_dump_tuples_proto(struct sk_buff *skb,
|
|
|
struct nf_conntrack_l4proto *l4proto)
|
|
|
{
|
|
|
int ret = 0;
|
|
|
- struct nfattr *nest_parms = NFA_NEST(skb, CTA_TUPLE_PROTO);
|
|
|
+ struct nlattr *nest_parms;
|
|
|
|
|
|
- NFA_PUT(skb, CTA_PROTO_NUM, sizeof(u_int8_t), &tuple->dst.protonum);
|
|
|
+ nest_parms = nla_nest_start(skb, CTA_TUPLE_PROTO | NLA_F_NESTED);
|
|
|
+ if (!nest_parms)
|
|
|
+ goto nla_put_failure;
|
|
|
+ NLA_PUT(skb, CTA_PROTO_NUM, sizeof(u_int8_t), &tuple->dst.protonum);
|
|
|
|
|
|
if (likely(l4proto->tuple_to_nfattr))
|
|
|
ret = l4proto->tuple_to_nfattr(skb, tuple);
|
|
|
|
|
|
- NFA_NEST_END(skb, nest_parms);
|
|
|
+ nla_nest_end(skb, nest_parms);
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
-nfattr_failure:
|
|
|
+nla_put_failure:
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
@@ -75,16 +78,20 @@ ctnetlink_dump_tuples_ip(struct sk_buff *skb,
|
|
|
struct nf_conntrack_l3proto *l3proto)
|
|
|
{
|
|
|
int ret = 0;
|
|
|
- struct nfattr *nest_parms = NFA_NEST(skb, CTA_TUPLE_IP);
|
|
|
+ struct nlattr *nest_parms;
|
|
|
+
|
|
|
+ nest_parms = nla_nest_start(skb, CTA_TUPLE_IP | NLA_F_NESTED);
|
|
|
+ if (!nest_parms)
|
|
|
+ goto nla_put_failure;
|
|
|
|
|
|
if (likely(l3proto->tuple_to_nfattr))
|
|
|
ret = l3proto->tuple_to_nfattr(skb, tuple);
|
|
|
|
|
|
- NFA_NEST_END(skb, nest_parms);
|
|
|
+ nla_nest_end(skb, nest_parms);
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
-nfattr_failure:
|
|
|
+nla_put_failure:
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
@@ -114,10 +121,10 @@ static inline int
|
|
|
ctnetlink_dump_status(struct sk_buff *skb, const struct nf_conn *ct)
|
|
|
{
|
|
|
__be32 status = htonl((u_int32_t) ct->status);
|
|
|
- NFA_PUT(skb, CTA_STATUS, sizeof(status), &status);
|
|
|
+ NLA_PUT(skb, CTA_STATUS, sizeof(status), &status);
|
|
|
return 0;
|
|
|
|
|
|
-nfattr_failure:
|
|
|
+nla_put_failure:
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
@@ -132,10 +139,10 @@ ctnetlink_dump_timeout(struct sk_buff *skb, const struct nf_conn *ct)
|
|
|
else
|
|
|
timeout = htonl(timeout_l / HZ);
|
|
|
|
|
|
- NFA_PUT(skb, CTA_TIMEOUT, sizeof(timeout), &timeout);
|
|
|
+ NLA_PUT(skb, CTA_TIMEOUT, sizeof(timeout), &timeout);
|
|
|
return 0;
|
|
|
|
|
|
-nfattr_failure:
|
|
|
+nla_put_failure:
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
@@ -143,7 +150,7 @@ static inline int
|
|
|
ctnetlink_dump_protoinfo(struct sk_buff *skb, const struct nf_conn *ct)
|
|
|
{
|
|
|
struct nf_conntrack_l4proto *l4proto = nf_ct_l4proto_find_get(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num, ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum);
|
|
|
- struct nfattr *nest_proto;
|
|
|
+ struct nlattr *nest_proto;
|
|
|
int ret;
|
|
|
|
|
|
if (!l4proto->to_nfattr) {
|
|
@@ -151,17 +158,19 @@ ctnetlink_dump_protoinfo(struct sk_buff *skb, const struct nf_conn *ct)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- nest_proto = NFA_NEST(skb, CTA_PROTOINFO);
|
|
|
+ nest_proto = nla_nest_start(skb, CTA_PROTOINFO | NLA_F_NESTED);
|
|
|
+ if (!nest_proto)
|
|
|
+ goto nla_put_failure;
|
|
|
|
|
|
ret = l4proto->to_nfattr(skb, nest_proto, ct);
|
|
|
|
|
|
nf_ct_l4proto_put(l4proto);
|
|
|
|
|
|
- NFA_NEST_END(skb, nest_proto);
|
|
|
+ nla_nest_end(skb, nest_proto);
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
-nfattr_failure:
|
|
|
+nla_put_failure:
|
|
|
nf_ct_l4proto_put(l4proto);
|
|
|
return -1;
|
|
|
}
|
|
@@ -169,7 +178,7 @@ nfattr_failure:
|
|
|
static inline int
|
|
|
ctnetlink_dump_helpinfo(struct sk_buff *skb, const struct nf_conn *ct)
|
|
|
{
|
|
|
- struct nfattr *nest_helper;
|
|
|
+ struct nlattr *nest_helper;
|
|
|
const struct nf_conn_help *help = nfct_help(ct);
|
|
|
struct nf_conntrack_helper *helper;
|
|
|
|
|
@@ -181,18 +190,20 @@ ctnetlink_dump_helpinfo(struct sk_buff *skb, const struct nf_conn *ct)
|
|
|
if (!helper)
|
|
|
goto out;
|
|
|
|
|
|
- nest_helper = NFA_NEST(skb, CTA_HELP);
|
|
|
- NFA_PUT(skb, CTA_HELP_NAME, strlen(helper->name), helper->name);
|
|
|
+ nest_helper = nla_nest_start(skb, CTA_HELP | NLA_F_NESTED);
|
|
|
+ if (!nest_helper)
|
|
|
+ goto nla_put_failure;
|
|
|
+ NLA_PUT(skb, CTA_HELP_NAME, strlen(helper->name), helper->name);
|
|
|
|
|
|
if (helper->to_nfattr)
|
|
|
helper->to_nfattr(skb, ct);
|
|
|
|
|
|
- NFA_NEST_END(skb, nest_helper);
|
|
|
+ nla_nest_end(skb, nest_helper);
|
|
|
out:
|
|
|
rcu_read_unlock();
|
|
|
return 0;
|
|
|
|
|
|
-nfattr_failure:
|
|
|
+nla_put_failure:
|
|
|
rcu_read_unlock();
|
|
|
return -1;
|
|
|
}
|
|
@@ -203,20 +214,24 @@ ctnetlink_dump_counters(struct sk_buff *skb, const struct nf_conn *ct,
|
|
|
enum ip_conntrack_dir dir)
|
|
|
{
|
|
|
enum ctattr_type type = dir ? CTA_COUNTERS_REPLY: CTA_COUNTERS_ORIG;
|
|
|
- struct nfattr *nest_count = NFA_NEST(skb, type);
|
|
|
+ struct nlattr *nest_count;
|
|
|
__be32 tmp;
|
|
|
|
|
|
+ nest_count = nla_nest_start(skb, type | NLA_F_NESTED);
|
|
|
+ if (!nest_count)
|
|
|
+ goto nla_put_failure;
|
|
|
+
|
|
|
tmp = htonl(ct->counters[dir].packets);
|
|
|
- NFA_PUT(skb, CTA_COUNTERS32_PACKETS, sizeof(u_int32_t), &tmp);
|
|
|
+ NLA_PUT(skb, CTA_COUNTERS32_PACKETS, sizeof(u_int32_t), &tmp);
|
|
|
|
|
|
tmp = htonl(ct->counters[dir].bytes);
|
|
|
- NFA_PUT(skb, CTA_COUNTERS32_BYTES, sizeof(u_int32_t), &tmp);
|
|
|
+ NLA_PUT(skb, CTA_COUNTERS32_BYTES, sizeof(u_int32_t), &tmp);
|
|
|
|
|
|
- NFA_NEST_END(skb, nest_count);
|
|
|
+ nla_nest_end(skb, nest_count);
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
-nfattr_failure:
|
|
|
+nla_put_failure:
|
|
|
return -1;
|
|
|
}
|
|
|
#else
|
|
@@ -229,10 +244,10 @@ ctnetlink_dump_mark(struct sk_buff *skb, const struct nf_conn *ct)
|
|
|
{
|
|
|
__be32 mark = htonl(ct->mark);
|
|
|
|
|
|
- NFA_PUT(skb, CTA_MARK, sizeof(u_int32_t), &mark);
|
|
|
+ NLA_PUT(skb, CTA_MARK, sizeof(u_int32_t), &mark);
|
|
|
return 0;
|
|
|
|
|
|
-nfattr_failure:
|
|
|
+nla_put_failure:
|
|
|
return -1;
|
|
|
}
|
|
|
#else
|
|
@@ -243,10 +258,10 @@ static inline int
|
|
|
ctnetlink_dump_id(struct sk_buff *skb, const struct nf_conn *ct)
|
|
|
{
|
|
|
__be32 id = htonl(ct->id);
|
|
|
- NFA_PUT(skb, CTA_ID, sizeof(u_int32_t), &id);
|
|
|
+ NLA_PUT(skb, CTA_ID, sizeof(u_int32_t), &id);
|
|
|
return 0;
|
|
|
|
|
|
-nfattr_failure:
|
|
|
+nla_put_failure:
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
@@ -255,10 +270,10 @@ ctnetlink_dump_use(struct sk_buff *skb, const struct nf_conn *ct)
|
|
|
{
|
|
|
__be32 use = htonl(atomic_read(&ct->ct_general.use));
|
|
|
|
|
|
- NFA_PUT(skb, CTA_USE, sizeof(u_int32_t), &use);
|
|
|
+ NLA_PUT(skb, CTA_USE, sizeof(u_int32_t), &use);
|
|
|
return 0;
|
|
|
|
|
|
-nfattr_failure:
|
|
|
+nla_put_failure:
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
@@ -271,7 +286,7 @@ ctnetlink_fill_info(struct sk_buff *skb, u32 pid, u32 seq,
|
|
|
{
|
|
|
struct nlmsghdr *nlh;
|
|
|
struct nfgenmsg *nfmsg;
|
|
|
- struct nfattr *nest_parms;
|
|
|
+ struct nlattr *nest_parms;
|
|
|
unsigned char *b = skb_tail_pointer(skb);
|
|
|
|
|
|
event |= NFNL_SUBSYS_CTNETLINK << 8;
|
|
@@ -284,15 +299,19 @@ ctnetlink_fill_info(struct sk_buff *skb, u32 pid, u32 seq,
|
|
|
nfmsg->version = NFNETLINK_V0;
|
|
|
nfmsg->res_id = 0;
|
|
|
|
|
|
- nest_parms = NFA_NEST(skb, CTA_TUPLE_ORIG);
|
|
|
+ nest_parms = nla_nest_start(skb, CTA_TUPLE_ORIG | NLA_F_NESTED);
|
|
|
+ if (!nest_parms)
|
|
|
+ goto nla_put_failure;
|
|
|
if (ctnetlink_dump_tuples(skb, tuple(ct, IP_CT_DIR_ORIGINAL)) < 0)
|
|
|
- goto nfattr_failure;
|
|
|
- NFA_NEST_END(skb, nest_parms);
|
|
|
+ goto nla_put_failure;
|
|
|
+ nla_nest_end(skb, nest_parms);
|
|
|
|
|
|
- nest_parms = NFA_NEST(skb, CTA_TUPLE_REPLY);
|
|
|
+ nest_parms = nla_nest_start(skb, CTA_TUPLE_REPLY | NLA_F_NESTED);
|
|
|
+ if (!nest_parms)
|
|
|
+ goto nla_put_failure;
|
|
|
if (ctnetlink_dump_tuples(skb, tuple(ct, IP_CT_DIR_REPLY)) < 0)
|
|
|
- goto nfattr_failure;
|
|
|
- NFA_NEST_END(skb, nest_parms);
|
|
|
+ goto nla_put_failure;
|
|
|
+ nla_nest_end(skb, nest_parms);
|
|
|
|
|
|
if (ctnetlink_dump_status(skb, ct) < 0 ||
|
|
|
ctnetlink_dump_timeout(skb, ct) < 0 ||
|
|
@@ -303,13 +322,13 @@ ctnetlink_fill_info(struct sk_buff *skb, u32 pid, u32 seq,
|
|
|
ctnetlink_dump_mark(skb, ct) < 0 ||
|
|
|
ctnetlink_dump_id(skb, ct) < 0 ||
|
|
|
ctnetlink_dump_use(skb, ct) < 0)
|
|
|
- goto nfattr_failure;
|
|
|
+ goto nla_put_failure;
|
|
|
|
|
|
nlh->nlmsg_len = skb_tail_pointer(skb) - b;
|
|
|
return skb->len;
|
|
|
|
|
|
nlmsg_failure:
|
|
|
-nfattr_failure:
|
|
|
+nla_put_failure:
|
|
|
nlmsg_trim(skb, b);
|
|
|
return -1;
|
|
|
}
|
|
@@ -320,7 +339,7 @@ static int ctnetlink_conntrack_event(struct notifier_block *this,
|
|
|
{
|
|
|
struct nlmsghdr *nlh;
|
|
|
struct nfgenmsg *nfmsg;
|
|
|
- struct nfattr *nest_parms;
|
|
|
+ struct nlattr *nest_parms;
|
|
|
struct nf_conn *ct = (struct nf_conn *)ptr;
|
|
|
struct sk_buff *skb;
|
|
|
unsigned int type;
|
|
@@ -362,45 +381,49 @@ static int ctnetlink_conntrack_event(struct notifier_block *this,
|
|
|
nfmsg->version = NFNETLINK_V0;
|
|
|
nfmsg->res_id = 0;
|
|
|
|
|
|
- nest_parms = NFA_NEST(skb, CTA_TUPLE_ORIG);
|
|
|
+ nest_parms = nla_nest_start(skb, CTA_TUPLE_ORIG | NLA_F_NESTED);
|
|
|
+ if (!nest_parms)
|
|
|
+ goto nla_put_failure;
|
|
|
if (ctnetlink_dump_tuples(skb, tuple(ct, IP_CT_DIR_ORIGINAL)) < 0)
|
|
|
- goto nfattr_failure;
|
|
|
- NFA_NEST_END(skb, nest_parms);
|
|
|
+ goto nla_put_failure;
|
|
|
+ nla_nest_end(skb, nest_parms);
|
|
|
|
|
|
- nest_parms = NFA_NEST(skb, CTA_TUPLE_REPLY);
|
|
|
+ nest_parms = nla_nest_start(skb, CTA_TUPLE_REPLY | NLA_F_NESTED);
|
|
|
+ if (!nest_parms)
|
|
|
+ goto nla_put_failure;
|
|
|
if (ctnetlink_dump_tuples(skb, tuple(ct, IP_CT_DIR_REPLY)) < 0)
|
|
|
- goto nfattr_failure;
|
|
|
- NFA_NEST_END(skb, nest_parms);
|
|
|
+ goto nla_put_failure;
|
|
|
+ nla_nest_end(skb, nest_parms);
|
|
|
|
|
|
if (events & IPCT_DESTROY) {
|
|
|
if (ctnetlink_dump_counters(skb, ct, IP_CT_DIR_ORIGINAL) < 0 ||
|
|
|
ctnetlink_dump_counters(skb, ct, IP_CT_DIR_REPLY) < 0)
|
|
|
- goto nfattr_failure;
|
|
|
+ goto nla_put_failure;
|
|
|
} else {
|
|
|
if (ctnetlink_dump_status(skb, ct) < 0)
|
|
|
- goto nfattr_failure;
|
|
|
+ goto nla_put_failure;
|
|
|
|
|
|
if (ctnetlink_dump_timeout(skb, ct) < 0)
|
|
|
- goto nfattr_failure;
|
|
|
+ goto nla_put_failure;
|
|
|
|
|
|
if (events & IPCT_PROTOINFO
|
|
|
&& ctnetlink_dump_protoinfo(skb, ct) < 0)
|
|
|
- goto nfattr_failure;
|
|
|
+ goto nla_put_failure;
|
|
|
|
|
|
if ((events & IPCT_HELPER || nfct_help(ct))
|
|
|
&& ctnetlink_dump_helpinfo(skb, ct) < 0)
|
|
|
- goto nfattr_failure;
|
|
|
+ goto nla_put_failure;
|
|
|
|
|
|
#ifdef CONFIG_NF_CONNTRACK_MARK
|
|
|
if ((events & IPCT_MARK || ct->mark)
|
|
|
&& ctnetlink_dump_mark(skb, ct) < 0)
|
|
|
- goto nfattr_failure;
|
|
|
+ goto nla_put_failure;
|
|
|
#endif
|
|
|
|
|
|
if (events & IPCT_COUNTER_FILLING &&
|
|
|
(ctnetlink_dump_counters(skb, ct, IP_CT_DIR_ORIGINAL) < 0 ||
|
|
|
ctnetlink_dump_counters(skb, ct, IP_CT_DIR_REPLY) < 0))
|
|
|
- goto nfattr_failure;
|
|
|
+ goto nla_put_failure;
|
|
|
}
|
|
|
|
|
|
nlh->nlmsg_len = skb->tail - b;
|
|
@@ -408,7 +431,7 @@ static int ctnetlink_conntrack_event(struct notifier_block *this,
|
|
|
return NOTIFY_DONE;
|
|
|
|
|
|
nlmsg_failure:
|
|
|
-nfattr_failure:
|
|
|
+nla_put_failure:
|
|
|
kfree_skb(skb);
|
|
|
return NOTIFY_DONE;
|
|
|
}
|
|
@@ -479,13 +502,13 @@ out:
|
|
|
}
|
|
|
|
|
|
static inline int
|
|
|
-ctnetlink_parse_tuple_ip(struct nfattr *attr, struct nf_conntrack_tuple *tuple)
|
|
|
+ctnetlink_parse_tuple_ip(struct nlattr *attr, struct nf_conntrack_tuple *tuple)
|
|
|
{
|
|
|
- struct nfattr *tb[CTA_IP_MAX];
|
|
|
+ struct nlattr *tb[CTA_IP_MAX+1];
|
|
|
struct nf_conntrack_l3proto *l3proto;
|
|
|
int ret = 0;
|
|
|
|
|
|
- nfattr_parse_nested(tb, CTA_IP_MAX, attr);
|
|
|
+ nla_parse_nested(tb, CTA_IP_MAX, attr, NULL);
|
|
|
|
|
|
l3proto = nf_ct_l3proto_find_get(tuple->src.l3num);
|
|
|
|
|
@@ -497,26 +520,26 @@ ctnetlink_parse_tuple_ip(struct nfattr *attr, struct nf_conntrack_tuple *tuple)
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-static const size_t cta_min_proto[CTA_PROTO_MAX] = {
|
|
|
- [CTA_PROTO_NUM-1] = sizeof(u_int8_t),
|
|
|
+static const size_t cta_min_proto[CTA_PROTO_MAX+1] = {
|
|
|
+ [CTA_PROTO_NUM] = sizeof(u_int8_t),
|
|
|
};
|
|
|
|
|
|
static inline int
|
|
|
-ctnetlink_parse_tuple_proto(struct nfattr *attr,
|
|
|
+ctnetlink_parse_tuple_proto(struct nlattr *attr,
|
|
|
struct nf_conntrack_tuple *tuple)
|
|
|
{
|
|
|
- struct nfattr *tb[CTA_PROTO_MAX];
|
|
|
+ struct nlattr *tb[CTA_PROTO_MAX+1];
|
|
|
struct nf_conntrack_l4proto *l4proto;
|
|
|
int ret = 0;
|
|
|
|
|
|
- nfattr_parse_nested(tb, CTA_PROTO_MAX, attr);
|
|
|
+ nla_parse_nested(tb, CTA_PROTO_MAX, attr, NULL);
|
|
|
|
|
|
if (nfattr_bad_size(tb, CTA_PROTO_MAX, cta_min_proto))
|
|
|
return -EINVAL;
|
|
|
|
|
|
- if (!tb[CTA_PROTO_NUM-1])
|
|
|
+ if (!tb[CTA_PROTO_NUM])
|
|
|
return -EINVAL;
|
|
|
- tuple->dst.protonum = *(u_int8_t *)NFA_DATA(tb[CTA_PROTO_NUM-1]);
|
|
|
+ tuple->dst.protonum = *(u_int8_t *)nla_data(tb[CTA_PROTO_NUM]);
|
|
|
|
|
|
l4proto = nf_ct_l4proto_find_get(tuple->src.l3num, tuple->dst.protonum);
|
|
|
|
|
@@ -529,29 +552,29 @@ ctnetlink_parse_tuple_proto(struct nfattr *attr,
|
|
|
}
|
|
|
|
|
|
static inline int
|
|
|
-ctnetlink_parse_tuple(struct nfattr *cda[], struct nf_conntrack_tuple *tuple,
|
|
|
+ctnetlink_parse_tuple(struct nlattr *cda[], struct nf_conntrack_tuple *tuple,
|
|
|
enum ctattr_tuple type, u_int8_t l3num)
|
|
|
{
|
|
|
- struct nfattr *tb[CTA_TUPLE_MAX];
|
|
|
+ struct nlattr *tb[CTA_TUPLE_MAX+1];
|
|
|
int err;
|
|
|
|
|
|
memset(tuple, 0, sizeof(*tuple));
|
|
|
|
|
|
- nfattr_parse_nested(tb, CTA_TUPLE_MAX, cda[type-1]);
|
|
|
+ nla_parse_nested(tb, CTA_TUPLE_MAX, cda[type], NULL);
|
|
|
|
|
|
- if (!tb[CTA_TUPLE_IP-1])
|
|
|
+ if (!tb[CTA_TUPLE_IP])
|
|
|
return -EINVAL;
|
|
|
|
|
|
tuple->src.l3num = l3num;
|
|
|
|
|
|
- err = ctnetlink_parse_tuple_ip(tb[CTA_TUPLE_IP-1], tuple);
|
|
|
+ err = ctnetlink_parse_tuple_ip(tb[CTA_TUPLE_IP], tuple);
|
|
|
if (err < 0)
|
|
|
return err;
|
|
|
|
|
|
- if (!tb[CTA_TUPLE_PROTO-1])
|
|
|
+ if (!tb[CTA_TUPLE_PROTO])
|
|
|
return -EINVAL;
|
|
|
|
|
|
- err = ctnetlink_parse_tuple_proto(tb[CTA_TUPLE_PROTO-1], tuple);
|
|
|
+ err = ctnetlink_parse_tuple_proto(tb[CTA_TUPLE_PROTO], tuple);
|
|
|
if (err < 0)
|
|
|
return err;
|
|
|
|
|
@@ -565,19 +588,19 @@ ctnetlink_parse_tuple(struct nfattr *cda[], struct nf_conntrack_tuple *tuple,
|
|
|
}
|
|
|
|
|
|
#ifdef CONFIG_NF_NAT_NEEDED
|
|
|
-static const size_t cta_min_protonat[CTA_PROTONAT_MAX] = {
|
|
|
- [CTA_PROTONAT_PORT_MIN-1] = sizeof(u_int16_t),
|
|
|
- [CTA_PROTONAT_PORT_MAX-1] = sizeof(u_int16_t),
|
|
|
+static const size_t cta_min_protonat[CTA_PROTONAT_MAX+1] = {
|
|
|
+ [CTA_PROTONAT_PORT_MIN] = sizeof(u_int16_t),
|
|
|
+ [CTA_PROTONAT_PORT_MAX] = sizeof(u_int16_t),
|
|
|
};
|
|
|
|
|
|
-static int nfnetlink_parse_nat_proto(struct nfattr *attr,
|
|
|
+static int nfnetlink_parse_nat_proto(struct nlattr *attr,
|
|
|
const struct nf_conn *ct,
|
|
|
struct nf_nat_range *range)
|
|
|
{
|
|
|
- struct nfattr *tb[CTA_PROTONAT_MAX];
|
|
|
+ struct nlattr *tb[CTA_PROTONAT_MAX+1];
|
|
|
struct nf_nat_protocol *npt;
|
|
|
|
|
|
- nfattr_parse_nested(tb, CTA_PROTONAT_MAX, attr);
|
|
|
+ nla_parse_nested(tb, CTA_PROTONAT_MAX, attr, NULL);
|
|
|
|
|
|
if (nfattr_bad_size(tb, CTA_PROTONAT_MAX, cta_min_protonat))
|
|
|
return -EINVAL;
|
|
@@ -598,40 +621,40 @@ static int nfnetlink_parse_nat_proto(struct nfattr *attr,
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static const size_t cta_min_nat[CTA_NAT_MAX] = {
|
|
|
- [CTA_NAT_MINIP-1] = sizeof(u_int32_t),
|
|
|
- [CTA_NAT_MAXIP-1] = sizeof(u_int32_t),
|
|
|
+static const size_t cta_min_nat[CTA_NAT_MAX+1] = {
|
|
|
+ [CTA_NAT_MINIP] = sizeof(u_int32_t),
|
|
|
+ [CTA_NAT_MAXIP] = sizeof(u_int32_t),
|
|
|
};
|
|
|
|
|
|
static inline int
|
|
|
-nfnetlink_parse_nat(struct nfattr *nat,
|
|
|
+nfnetlink_parse_nat(struct nlattr *nat,
|
|
|
const struct nf_conn *ct, struct nf_nat_range *range)
|
|
|
{
|
|
|
- struct nfattr *tb[CTA_NAT_MAX];
|
|
|
+ struct nlattr *tb[CTA_NAT_MAX+1];
|
|
|
int err;
|
|
|
|
|
|
memset(range, 0, sizeof(*range));
|
|
|
|
|
|
- nfattr_parse_nested(tb, CTA_NAT_MAX, nat);
|
|
|
+ nla_parse_nested(tb, CTA_NAT_MAX, nat, NULL);
|
|
|
|
|
|
if (nfattr_bad_size(tb, CTA_NAT_MAX, cta_min_nat))
|
|
|
return -EINVAL;
|
|
|
|
|
|
- if (tb[CTA_NAT_MINIP-1])
|
|
|
- range->min_ip = *(__be32 *)NFA_DATA(tb[CTA_NAT_MINIP-1]);
|
|
|
+ if (tb[CTA_NAT_MINIP])
|
|
|
+ range->min_ip = *(__be32 *)nla_data(tb[CTA_NAT_MINIP]);
|
|
|
|
|
|
- if (!tb[CTA_NAT_MAXIP-1])
|
|
|
+ if (!tb[CTA_NAT_MAXIP])
|
|
|
range->max_ip = range->min_ip;
|
|
|
else
|
|
|
- range->max_ip = *(__be32 *)NFA_DATA(tb[CTA_NAT_MAXIP-1]);
|
|
|
+ range->max_ip = *(__be32 *)nla_data(tb[CTA_NAT_MAXIP]);
|
|
|
|
|
|
if (range->min_ip)
|
|
|
range->flags |= IP_NAT_RANGE_MAP_IPS;
|
|
|
|
|
|
- if (!tb[CTA_NAT_PROTO-1])
|
|
|
+ if (!tb[CTA_NAT_PROTO])
|
|
|
return 0;
|
|
|
|
|
|
- err = nfnetlink_parse_nat_proto(tb[CTA_NAT_PROTO-1], ct, range);
|
|
|
+ err = nfnetlink_parse_nat_proto(tb[CTA_NAT_PROTO], ct, range);
|
|
|
if (err < 0)
|
|
|
return err;
|
|
|
|
|
@@ -640,31 +663,31 @@ nfnetlink_parse_nat(struct nfattr *nat,
|
|
|
#endif
|
|
|
|
|
|
static inline int
|
|
|
-ctnetlink_parse_help(struct nfattr *attr, char **helper_name)
|
|
|
+ctnetlink_parse_help(struct nlattr *attr, char **helper_name)
|
|
|
{
|
|
|
- struct nfattr *tb[CTA_HELP_MAX];
|
|
|
+ struct nlattr *tb[CTA_HELP_MAX+1];
|
|
|
|
|
|
- nfattr_parse_nested(tb, CTA_HELP_MAX, attr);
|
|
|
+ nla_parse_nested(tb, CTA_HELP_MAX, attr, NULL);
|
|
|
|
|
|
- if (!tb[CTA_HELP_NAME-1])
|
|
|
+ if (!tb[CTA_HELP_NAME])
|
|
|
return -EINVAL;
|
|
|
|
|
|
- *helper_name = NFA_DATA(tb[CTA_HELP_NAME-1]);
|
|
|
+ *helper_name = nla_data(tb[CTA_HELP_NAME]);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static const size_t cta_min[CTA_MAX] = {
|
|
|
- [CTA_STATUS-1] = sizeof(u_int32_t),
|
|
|
- [CTA_TIMEOUT-1] = sizeof(u_int32_t),
|
|
|
- [CTA_MARK-1] = sizeof(u_int32_t),
|
|
|
- [CTA_USE-1] = sizeof(u_int32_t),
|
|
|
- [CTA_ID-1] = sizeof(u_int32_t)
|
|
|
+static const size_t cta_min[CTA_MAX+1] = {
|
|
|
+ [CTA_STATUS] = sizeof(u_int32_t),
|
|
|
+ [CTA_TIMEOUT] = sizeof(u_int32_t),
|
|
|
+ [CTA_MARK] = sizeof(u_int32_t),
|
|
|
+ [CTA_USE] = sizeof(u_int32_t),
|
|
|
+ [CTA_ID] = sizeof(u_int32_t)
|
|
|
};
|
|
|
|
|
|
static int
|
|
|
ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
|
|
|
- struct nlmsghdr *nlh, struct nfattr *cda[])
|
|
|
+ struct nlmsghdr *nlh, struct nlattr *cda[])
|
|
|
{
|
|
|
struct nf_conntrack_tuple_hash *h;
|
|
|
struct nf_conntrack_tuple tuple;
|
|
@@ -676,9 +699,9 @@ ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
|
|
|
if (nfattr_bad_size(cda, CTA_MAX, cta_min))
|
|
|
return -EINVAL;
|
|
|
|
|
|
- if (cda[CTA_TUPLE_ORIG-1])
|
|
|
+ if (cda[CTA_TUPLE_ORIG])
|
|
|
err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_ORIG, u3);
|
|
|
- else if (cda[CTA_TUPLE_REPLY-1])
|
|
|
+ else if (cda[CTA_TUPLE_REPLY])
|
|
|
err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_REPLY, u3);
|
|
|
else {
|
|
|
/* Flush the whole table */
|
|
@@ -695,8 +718,8 @@ ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
|
|
|
|
|
|
ct = nf_ct_tuplehash_to_ctrack(h);
|
|
|
|
|
|
- if (cda[CTA_ID-1]) {
|
|
|
- u_int32_t id = ntohl(*(__be32 *)NFA_DATA(cda[CTA_ID-1]));
|
|
|
+ if (cda[CTA_ID]) {
|
|
|
+ u_int32_t id = ntohl(*(__be32 *)nla_data(cda[CTA_ID]));
|
|
|
if (ct->id != id) {
|
|
|
nf_ct_put(ct);
|
|
|
return -ENOENT;
|
|
@@ -712,7 +735,7 @@ ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
|
|
|
|
|
|
static int
|
|
|
ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
|
|
|
- struct nlmsghdr *nlh, struct nfattr *cda[])
|
|
|
+ struct nlmsghdr *nlh, struct nlattr *cda[])
|
|
|
{
|
|
|
struct nf_conntrack_tuple_hash *h;
|
|
|
struct nf_conntrack_tuple tuple;
|
|
@@ -734,9 +757,9 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
|
|
|
if (nfattr_bad_size(cda, CTA_MAX, cta_min))
|
|
|
return -EINVAL;
|
|
|
|
|
|
- if (cda[CTA_TUPLE_ORIG-1])
|
|
|
+ if (cda[CTA_TUPLE_ORIG])
|
|
|
err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_ORIG, u3);
|
|
|
- else if (cda[CTA_TUPLE_REPLY-1])
|
|
|
+ else if (cda[CTA_TUPLE_REPLY])
|
|
|
err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_REPLY, u3);
|
|
|
else
|
|
|
return -EINVAL;
|
|
@@ -776,10 +799,10 @@ out:
|
|
|
}
|
|
|
|
|
|
static inline int
|
|
|
-ctnetlink_change_status(struct nf_conn *ct, struct nfattr *cda[])
|
|
|
+ctnetlink_change_status(struct nf_conn *ct, struct nlattr *cda[])
|
|
|
{
|
|
|
unsigned long d;
|
|
|
- unsigned int status = ntohl(*(__be32 *)NFA_DATA(cda[CTA_STATUS-1]));
|
|
|
+ unsigned int status = ntohl(*(__be32 *)nla_data(cda[CTA_STATUS]));
|
|
|
d = ct->status ^ status;
|
|
|
|
|
|
if (d & (IPS_EXPECTED|IPS_CONFIRMED|IPS_DYING))
|
|
@@ -795,14 +818,14 @@ ctnetlink_change_status(struct nf_conn *ct, struct nfattr *cda[])
|
|
|
/* ASSURED bit can only be set */
|
|
|
return -EINVAL;
|
|
|
|
|
|
- if (cda[CTA_NAT_SRC-1] || cda[CTA_NAT_DST-1]) {
|
|
|
+ if (cda[CTA_NAT_SRC] || cda[CTA_NAT_DST]) {
|
|
|
#ifndef CONFIG_NF_NAT_NEEDED
|
|
|
return -EINVAL;
|
|
|
#else
|
|
|
struct nf_nat_range range;
|
|
|
|
|
|
- if (cda[CTA_NAT_DST-1]) {
|
|
|
- if (nfnetlink_parse_nat(cda[CTA_NAT_DST-1], ct,
|
|
|
+ if (cda[CTA_NAT_DST]) {
|
|
|
+ if (nfnetlink_parse_nat(cda[CTA_NAT_DST], ct,
|
|
|
&range) < 0)
|
|
|
return -EINVAL;
|
|
|
if (nf_nat_initialized(ct,
|
|
@@ -810,8 +833,8 @@ ctnetlink_change_status(struct nf_conn *ct, struct nfattr *cda[])
|
|
|
return -EEXIST;
|
|
|
nf_nat_setup_info(ct, &range, NF_IP_PRE_ROUTING);
|
|
|
}
|
|
|
- if (cda[CTA_NAT_SRC-1]) {
|
|
|
- if (nfnetlink_parse_nat(cda[CTA_NAT_SRC-1], ct,
|
|
|
+ if (cda[CTA_NAT_SRC]) {
|
|
|
+ if (nfnetlink_parse_nat(cda[CTA_NAT_SRC], ct,
|
|
|
&range) < 0)
|
|
|
return -EINVAL;
|
|
|
if (nf_nat_initialized(ct,
|
|
@@ -831,7 +854,7 @@ ctnetlink_change_status(struct nf_conn *ct, struct nfattr *cda[])
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
-ctnetlink_change_helper(struct nf_conn *ct, struct nfattr *cda[])
|
|
|
+ctnetlink_change_helper(struct nf_conn *ct, struct nlattr *cda[])
|
|
|
{
|
|
|
struct nf_conntrack_helper *helper;
|
|
|
struct nf_conn_help *help = nfct_help(ct);
|
|
@@ -842,7 +865,7 @@ ctnetlink_change_helper(struct nf_conn *ct, struct nfattr *cda[])
|
|
|
if (ct->master)
|
|
|
return -EINVAL;
|
|
|
|
|
|
- err = ctnetlink_parse_help(cda[CTA_HELP-1], &helpname);
|
|
|
+ err = ctnetlink_parse_help(cda[CTA_HELP], &helpname);
|
|
|
if (err < 0)
|
|
|
return err;
|
|
|
|
|
@@ -879,9 +902,9 @@ ctnetlink_change_helper(struct nf_conn *ct, struct nfattr *cda[])
|
|
|
}
|
|
|
|
|
|
static inline int
|
|
|
-ctnetlink_change_timeout(struct nf_conn *ct, struct nfattr *cda[])
|
|
|
+ctnetlink_change_timeout(struct nf_conn *ct, struct nlattr *cda[])
|
|
|
{
|
|
|
- u_int32_t timeout = ntohl(*(__be32 *)NFA_DATA(cda[CTA_TIMEOUT-1]));
|
|
|
+ u_int32_t timeout = ntohl(*(__be32 *)nla_data(cda[CTA_TIMEOUT]));
|
|
|
|
|
|
if (!del_timer(&ct->timeout))
|
|
|
return -ETIME;
|
|
@@ -893,15 +916,15 @@ ctnetlink_change_timeout(struct nf_conn *ct, struct nfattr *cda[])
|
|
|
}
|
|
|
|
|
|
static inline int
|
|
|
-ctnetlink_change_protoinfo(struct nf_conn *ct, struct nfattr *cda[])
|
|
|
+ctnetlink_change_protoinfo(struct nf_conn *ct, struct nlattr *cda[])
|
|
|
{
|
|
|
- struct nfattr *tb[CTA_PROTOINFO_MAX], *attr = cda[CTA_PROTOINFO-1];
|
|
|
+ struct nlattr *tb[CTA_PROTOINFO_MAX+1], *attr = cda[CTA_PROTOINFO];
|
|
|
struct nf_conntrack_l4proto *l4proto;
|
|
|
u_int16_t npt = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum;
|
|
|
u_int16_t l3num = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num;
|
|
|
int err = 0;
|
|
|
|
|
|
- nfattr_parse_nested(tb, CTA_PROTOINFO_MAX, attr);
|
|
|
+ nla_parse_nested(tb, CTA_PROTOINFO_MAX, attr, NULL);
|
|
|
|
|
|
l4proto = nf_ct_l4proto_find_get(l3num, npt);
|
|
|
|
|
@@ -913,44 +936,44 @@ ctnetlink_change_protoinfo(struct nf_conn *ct, struct nfattr *cda[])
|
|
|
}
|
|
|
|
|
|
static int
|
|
|
-ctnetlink_change_conntrack(struct nf_conn *ct, struct nfattr *cda[])
|
|
|
+ctnetlink_change_conntrack(struct nf_conn *ct, struct nlattr *cda[])
|
|
|
{
|
|
|
int err;
|
|
|
|
|
|
- if (cda[CTA_HELP-1]) {
|
|
|
+ if (cda[CTA_HELP]) {
|
|
|
err = ctnetlink_change_helper(ct, cda);
|
|
|
if (err < 0)
|
|
|
return err;
|
|
|
}
|
|
|
|
|
|
- if (cda[CTA_TIMEOUT-1]) {
|
|
|
+ if (cda[CTA_TIMEOUT]) {
|
|
|
err = ctnetlink_change_timeout(ct, cda);
|
|
|
if (err < 0)
|
|
|
return err;
|
|
|
}
|
|
|
|
|
|
- if (cda[CTA_STATUS-1]) {
|
|
|
+ if (cda[CTA_STATUS]) {
|
|
|
err = ctnetlink_change_status(ct, cda);
|
|
|
if (err < 0)
|
|
|
return err;
|
|
|
}
|
|
|
|
|
|
- if (cda[CTA_PROTOINFO-1]) {
|
|
|
+ if (cda[CTA_PROTOINFO]) {
|
|
|
err = ctnetlink_change_protoinfo(ct, cda);
|
|
|
if (err < 0)
|
|
|
return err;
|
|
|
}
|
|
|
|
|
|
#if defined(CONFIG_NF_CONNTRACK_MARK)
|
|
|
- if (cda[CTA_MARK-1])
|
|
|
- ct->mark = ntohl(*(__be32 *)NFA_DATA(cda[CTA_MARK-1]));
|
|
|
+ if (cda[CTA_MARK])
|
|
|
+ ct->mark = ntohl(*(__be32 *)nla_data(cda[CTA_MARK]));
|
|
|
#endif
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
static int
|
|
|
-ctnetlink_create_conntrack(struct nfattr *cda[],
|
|
|
+ctnetlink_create_conntrack(struct nlattr *cda[],
|
|
|
struct nf_conntrack_tuple *otuple,
|
|
|
struct nf_conntrack_tuple *rtuple)
|
|
|
{
|
|
@@ -963,28 +986,28 @@ ctnetlink_create_conntrack(struct nfattr *cda[],
|
|
|
if (ct == NULL || IS_ERR(ct))
|
|
|
return -ENOMEM;
|
|
|
|
|
|
- if (!cda[CTA_TIMEOUT-1])
|
|
|
+ if (!cda[CTA_TIMEOUT])
|
|
|
goto err;
|
|
|
- ct->timeout.expires = ntohl(*(__be32 *)NFA_DATA(cda[CTA_TIMEOUT-1]));
|
|
|
+ ct->timeout.expires = ntohl(*(__be32 *)nla_data(cda[CTA_TIMEOUT]));
|
|
|
|
|
|
ct->timeout.expires = jiffies + ct->timeout.expires * HZ;
|
|
|
ct->status |= IPS_CONFIRMED;
|
|
|
|
|
|
- if (cda[CTA_STATUS-1]) {
|
|
|
+ if (cda[CTA_STATUS]) {
|
|
|
err = ctnetlink_change_status(ct, cda);
|
|
|
if (err < 0)
|
|
|
goto err;
|
|
|
}
|
|
|
|
|
|
- if (cda[CTA_PROTOINFO-1]) {
|
|
|
+ if (cda[CTA_PROTOINFO]) {
|
|
|
err = ctnetlink_change_protoinfo(ct, cda);
|
|
|
if (err < 0)
|
|
|
goto err;
|
|
|
}
|
|
|
|
|
|
#if defined(CONFIG_NF_CONNTRACK_MARK)
|
|
|
- if (cda[CTA_MARK-1])
|
|
|
- ct->mark = ntohl(*(__be32 *)NFA_DATA(cda[CTA_MARK-1]));
|
|
|
+ if (cda[CTA_MARK])
|
|
|
+ ct->mark = ntohl(*(__be32 *)nla_data(cda[CTA_MARK]));
|
|
|
#endif
|
|
|
|
|
|
helper = nf_ct_helper_find_get(rtuple);
|
|
@@ -1014,7 +1037,7 @@ err:
|
|
|
|
|
|
static int
|
|
|
ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
|
|
|
- struct nlmsghdr *nlh, struct nfattr *cda[])
|
|
|
+ struct nlmsghdr *nlh, struct nlattr *cda[])
|
|
|
{
|
|
|
struct nf_conntrack_tuple otuple, rtuple;
|
|
|
struct nf_conntrack_tuple_hash *h = NULL;
|
|
@@ -1025,22 +1048,22 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
|
|
|
if (nfattr_bad_size(cda, CTA_MAX, cta_min))
|
|
|
return -EINVAL;
|
|
|
|
|
|
- if (cda[CTA_TUPLE_ORIG-1]) {
|
|
|
+ if (cda[CTA_TUPLE_ORIG]) {
|
|
|
err = ctnetlink_parse_tuple(cda, &otuple, CTA_TUPLE_ORIG, u3);
|
|
|
if (err < 0)
|
|
|
return err;
|
|
|
}
|
|
|
|
|
|
- if (cda[CTA_TUPLE_REPLY-1]) {
|
|
|
+ if (cda[CTA_TUPLE_REPLY]) {
|
|
|
err = ctnetlink_parse_tuple(cda, &rtuple, CTA_TUPLE_REPLY, u3);
|
|
|
if (err < 0)
|
|
|
return err;
|
|
|
}
|
|
|
|
|
|
write_lock_bh(&nf_conntrack_lock);
|
|
|
- if (cda[CTA_TUPLE_ORIG-1])
|
|
|
+ if (cda[CTA_TUPLE_ORIG])
|
|
|
h = __nf_conntrack_find(&otuple, NULL);
|
|
|
- else if (cda[CTA_TUPLE_REPLY-1])
|
|
|
+ else if (cda[CTA_TUPLE_REPLY])
|
|
|
h = __nf_conntrack_find(&rtuple, NULL);
|
|
|
|
|
|
if (h == NULL) {
|
|
@@ -1057,7 +1080,7 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
|
|
|
err = -EEXIST;
|
|
|
if (!(nlh->nlmsg_flags & NLM_F_EXCL)) {
|
|
|
/* we only allow nat config for new conntracks */
|
|
|
- if (cda[CTA_NAT_SRC-1] || cda[CTA_NAT_DST-1]) {
|
|
|
+ if (cda[CTA_NAT_SRC] || cda[CTA_NAT_DST]) {
|
|
|
err = -EINVAL;
|
|
|
goto out_unlock;
|
|
|
}
|
|
@@ -1079,16 +1102,18 @@ ctnetlink_exp_dump_tuple(struct sk_buff *skb,
|
|
|
const struct nf_conntrack_tuple *tuple,
|
|
|
enum ctattr_expect type)
|
|
|
{
|
|
|
- struct nfattr *nest_parms = NFA_NEST(skb, type);
|
|
|
+ struct nlattr *nest_parms;
|
|
|
|
|
|
+ nest_parms = nla_nest_start(skb, type | NLA_F_NESTED);
|
|
|
+ if (!nest_parms)
|
|
|
+ goto nla_put_failure;
|
|
|
if (ctnetlink_dump_tuples(skb, tuple) < 0)
|
|
|
- goto nfattr_failure;
|
|
|
-
|
|
|
- NFA_NEST_END(skb, nest_parms);
|
|
|
+ goto nla_put_failure;
|
|
|
+ nla_nest_end(skb, nest_parms);
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
-nfattr_failure:
|
|
|
+nla_put_failure:
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
@@ -1101,32 +1126,34 @@ ctnetlink_exp_dump_mask(struct sk_buff *skb,
|
|
|
struct nf_conntrack_l3proto *l3proto;
|
|
|
struct nf_conntrack_l4proto *l4proto;
|
|
|
struct nf_conntrack_tuple m;
|
|
|
- struct nfattr *nest_parms;
|
|
|
+ struct nlattr *nest_parms;
|
|
|
|
|
|
memset(&m, 0xFF, sizeof(m));
|
|
|
m.src.u.all = mask->src.u.all;
|
|
|
memcpy(&m.src.u3, &mask->src.u3, sizeof(m.src.u3));
|
|
|
|
|
|
- nest_parms = NFA_NEST(skb, CTA_EXPECT_MASK);
|
|
|
+ nest_parms = nla_nest_start(skb, CTA_EXPECT_MASK | NLA_F_NESTED);
|
|
|
+ if (!nest_parms)
|
|
|
+ goto nla_put_failure;
|
|
|
|
|
|
l3proto = nf_ct_l3proto_find_get(tuple->src.l3num);
|
|
|
ret = ctnetlink_dump_tuples_ip(skb, &m, l3proto);
|
|
|
nf_ct_l3proto_put(l3proto);
|
|
|
|
|
|
if (unlikely(ret < 0))
|
|
|
- goto nfattr_failure;
|
|
|
+ goto nla_put_failure;
|
|
|
|
|
|
l4proto = nf_ct_l4proto_find_get(tuple->src.l3num, tuple->dst.protonum);
|
|
|
ret = ctnetlink_dump_tuples_proto(skb, &m, l4proto);
|
|
|
nf_ct_l4proto_put(l4proto);
|
|
|
if (unlikely(ret < 0))
|
|
|
- goto nfattr_failure;
|
|
|
+ goto nla_put_failure;
|
|
|
|
|
|
- NFA_NEST_END(skb, nest_parms);
|
|
|
+ nla_nest_end(skb, nest_parms);
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
-nfattr_failure:
|
|
|
+nla_put_failure:
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
@@ -1139,20 +1166,20 @@ ctnetlink_exp_dump_expect(struct sk_buff *skb,
|
|
|
__be32 id = htonl(exp->id);
|
|
|
|
|
|
if (ctnetlink_exp_dump_tuple(skb, &exp->tuple, CTA_EXPECT_TUPLE) < 0)
|
|
|
- goto nfattr_failure;
|
|
|
+ goto nla_put_failure;
|
|
|
if (ctnetlink_exp_dump_mask(skb, &exp->tuple, &exp->mask) < 0)
|
|
|
- goto nfattr_failure;
|
|
|
+ goto nla_put_failure;
|
|
|
if (ctnetlink_exp_dump_tuple(skb,
|
|
|
&master->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
|
|
|
CTA_EXPECT_MASTER) < 0)
|
|
|
- goto nfattr_failure;
|
|
|
+ goto nla_put_failure;
|
|
|
|
|
|
- NFA_PUT(skb, CTA_EXPECT_TIMEOUT, sizeof(timeout), &timeout);
|
|
|
- NFA_PUT(skb, CTA_EXPECT_ID, sizeof(u_int32_t), &id);
|
|
|
+ NLA_PUT(skb, CTA_EXPECT_TIMEOUT, sizeof(timeout), &timeout);
|
|
|
+ NLA_PUT(skb, CTA_EXPECT_ID, sizeof(u_int32_t), &id);
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
-nfattr_failure:
|
|
|
+nla_put_failure:
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
@@ -1176,13 +1203,13 @@ ctnetlink_exp_fill_info(struct sk_buff *skb, u32 pid, u32 seq,
|
|
|
nfmsg->res_id = 0;
|
|
|
|
|
|
if (ctnetlink_exp_dump_expect(skb, exp) < 0)
|
|
|
- goto nfattr_failure;
|
|
|
+ goto nla_put_failure;
|
|
|
|
|
|
nlh->nlmsg_len = skb_tail_pointer(skb) - b;
|
|
|
return skb->len;
|
|
|
|
|
|
nlmsg_failure:
|
|
|
-nfattr_failure:
|
|
|
+nla_put_failure:
|
|
|
nlmsg_trim(skb, b);
|
|
|
return -1;
|
|
|
}
|
|
@@ -1224,14 +1251,14 @@ static int ctnetlink_expect_event(struct notifier_block *this,
|
|
|
nfmsg->res_id = 0;
|
|
|
|
|
|
if (ctnetlink_exp_dump_expect(skb, exp) < 0)
|
|
|
- goto nfattr_failure;
|
|
|
+ goto nla_put_failure;
|
|
|
|
|
|
nlh->nlmsg_len = skb->tail - b;
|
|
|
nfnetlink_send(skb, 0, NFNLGRP_CONNTRACK_EXP_NEW, 0);
|
|
|
return NOTIFY_DONE;
|
|
|
|
|
|
nlmsg_failure:
|
|
|
-nfattr_failure:
|
|
|
+nla_put_failure:
|
|
|
kfree_skb(skb);
|
|
|
return NOTIFY_DONE;
|
|
|
}
|
|
@@ -1286,14 +1313,14 @@ out:
|
|
|
return skb->len;
|
|
|
}
|
|
|
|
|
|
-static const size_t cta_min_exp[CTA_EXPECT_MAX] = {
|
|
|
- [CTA_EXPECT_TIMEOUT-1] = sizeof(u_int32_t),
|
|
|
- [CTA_EXPECT_ID-1] = sizeof(u_int32_t)
|
|
|
+static const size_t cta_min_exp[CTA_EXPECT_MAX+1] = {
|
|
|
+ [CTA_EXPECT_TIMEOUT] = sizeof(u_int32_t),
|
|
|
+ [CTA_EXPECT_ID] = sizeof(u_int32_t)
|
|
|
};
|
|
|
|
|
|
static int
|
|
|
ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
|
|
|
- struct nlmsghdr *nlh, struct nfattr *cda[])
|
|
|
+ struct nlmsghdr *nlh, struct nlattr *cda[])
|
|
|
{
|
|
|
struct nf_conntrack_tuple tuple;
|
|
|
struct nf_conntrack_expect *exp;
|
|
@@ -1311,7 +1338,7 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
|
|
|
ctnetlink_exp_done);
|
|
|
}
|
|
|
|
|
|
- if (cda[CTA_EXPECT_MASTER-1])
|
|
|
+ if (cda[CTA_EXPECT_MASTER])
|
|
|
err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_MASTER, u3);
|
|
|
else
|
|
|
return -EINVAL;
|
|
@@ -1323,8 +1350,8 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
|
|
|
if (!exp)
|
|
|
return -ENOENT;
|
|
|
|
|
|
- if (cda[CTA_EXPECT_ID-1]) {
|
|
|
- __be32 id = *(__be32 *)NFA_DATA(cda[CTA_EXPECT_ID-1]);
|
|
|
+ if (cda[CTA_EXPECT_ID]) {
|
|
|
+ __be32 id = *(__be32 *)nla_data(cda[CTA_EXPECT_ID]);
|
|
|
if (exp->id != ntohl(id)) {
|
|
|
nf_ct_expect_put(exp);
|
|
|
return -ENOENT;
|
|
@@ -1355,7 +1382,7 @@ out:
|
|
|
|
|
|
static int
|
|
|
ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,
|
|
|
- struct nlmsghdr *nlh, struct nfattr *cda[])
|
|
|
+ struct nlmsghdr *nlh, struct nlattr *cda[])
|
|
|
{
|
|
|
struct nf_conntrack_expect *exp;
|
|
|
struct nf_conntrack_tuple tuple;
|
|
@@ -1369,7 +1396,7 @@ ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,
|
|
|
if (nfattr_bad_size(cda, CTA_EXPECT_MAX, cta_min_exp))
|
|
|
return -EINVAL;
|
|
|
|
|
|
- if (cda[CTA_EXPECT_TUPLE-1]) {
|
|
|
+ if (cda[CTA_EXPECT_TUPLE]) {
|
|
|
/* delete a single expect by tuple */
|
|
|
err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3);
|
|
|
if (err < 0)
|
|
@@ -1380,8 +1407,8 @@ ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,
|
|
|
if (!exp)
|
|
|
return -ENOENT;
|
|
|
|
|
|
- if (cda[CTA_EXPECT_ID-1]) {
|
|
|
- __be32 id = *(__be32 *)NFA_DATA(cda[CTA_EXPECT_ID-1]);
|
|
|
+ if (cda[CTA_EXPECT_ID]) {
|
|
|
+ __be32 id = *(__be32 *)nla_data(cda[CTA_EXPECT_ID]);
|
|
|
if (exp->id != ntohl(id)) {
|
|
|
nf_ct_expect_put(exp);
|
|
|
return -ENOENT;
|
|
@@ -1393,8 +1420,8 @@ ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,
|
|
|
/* have to put what we 'get' above.
|
|
|
* after this line usage count == 0 */
|
|
|
nf_ct_expect_put(exp);
|
|
|
- } else if (cda[CTA_EXPECT_HELP_NAME-1]) {
|
|
|
- char *name = NFA_DATA(cda[CTA_EXPECT_HELP_NAME-1]);
|
|
|
+ } else if (cda[CTA_EXPECT_HELP_NAME]) {
|
|
|
+ char *name = nla_data(cda[CTA_EXPECT_HELP_NAME]);
|
|
|
struct nf_conn_help *m_help;
|
|
|
|
|
|
/* delete all expectations for this helper */
|
|
@@ -1436,13 +1463,13 @@ ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,
|
|
|
return 0;
|
|
|
}
|
|
|
static int
|
|
|
-ctnetlink_change_expect(struct nf_conntrack_expect *x, struct nfattr *cda[])
|
|
|
+ctnetlink_change_expect(struct nf_conntrack_expect *x, struct nlattr *cda[])
|
|
|
{
|
|
|
return -EOPNOTSUPP;
|
|
|
}
|
|
|
|
|
|
static int
|
|
|
-ctnetlink_create_expect(struct nfattr *cda[], u_int8_t u3)
|
|
|
+ctnetlink_create_expect(struct nlattr *cda[], u_int8_t u3)
|
|
|
{
|
|
|
struct nf_conntrack_tuple tuple, mask, master_tuple;
|
|
|
struct nf_conntrack_tuple_hash *h = NULL;
|
|
@@ -1499,7 +1526,7 @@ out:
|
|
|
|
|
|
static int
|
|
|
ctnetlink_new_expect(struct sock *ctnl, struct sk_buff *skb,
|
|
|
- struct nlmsghdr *nlh, struct nfattr *cda[])
|
|
|
+ struct nlmsghdr *nlh, struct nlattr *cda[])
|
|
|
{
|
|
|
struct nf_conntrack_tuple tuple;
|
|
|
struct nf_conntrack_expect *exp;
|
|
@@ -1510,9 +1537,9 @@ ctnetlink_new_expect(struct sock *ctnl, struct sk_buff *skb,
|
|
|
if (nfattr_bad_size(cda, CTA_EXPECT_MAX, cta_min_exp))
|
|
|
return -EINVAL;
|
|
|
|
|
|
- if (!cda[CTA_EXPECT_TUPLE-1]
|
|
|
- || !cda[CTA_EXPECT_MASK-1]
|
|
|
- || !cda[CTA_EXPECT_MASTER-1])
|
|
|
+ if (!cda[CTA_EXPECT_TUPLE]
|
|
|
+ || !cda[CTA_EXPECT_MASK]
|
|
|
+ || !cda[CTA_EXPECT_MASTER])
|
|
|
return -EINVAL;
|
|
|
|
|
|
err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3);
|