Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 328081
b: refs/heads/master
c: 7be54ca
h: refs/heads/master
i:
  328079: 90c9aed
v: v3
  • Loading branch information
Pablo Neira Ayuso committed Sep 24, 2012
1 parent a800c35 commit bb208fb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 54eb3df3a7d01b6cd395bdc1098280f2f93fbec5
refs/heads/master: 7be54ca4764bdead40bee7b645a72718c20ff2c8
6 changes: 5 additions & 1 deletion trunk/include/linux/netfilter/nf_conntrack_ftp.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ enum nf_ct_ftp_type {

#define FTP_PORT 21

#define NF_CT_FTP_SEQ_PICKUP (1 << 0)

#define NUM_SEQ_TO_REMEMBER 2
/* This structure exists only once per master */
struct nf_ct_ftp_master {
/* Valid seq positions for cmd matching after newline */
u_int32_t seq_aft_nl[IP_CT_DIR_MAX][NUM_SEQ_TO_REMEMBER];
/* 0 means seq_match_aft_nl not set */
int seq_aft_nl_num[IP_CT_DIR_MAX];
u_int16_t seq_aft_nl_num[IP_CT_DIR_MAX];
/* pickup sequence tracking, useful for conntrackd */
u_int16_t flags[IP_CT_DIR_MAX];
};

struct nf_conntrack_expect;
Expand Down
21 changes: 21 additions & 0 deletions trunk/net/netfilter/nf_conntrack_ftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,12 @@ static int help(struct sk_buff *skb,

/* Look up to see if we're just after a \n. */
if (!find_nl_seq(ntohl(th->seq), ct_ftp_info, dir)) {
/* We're picking up this, clear flags and let it continue */
if (unlikely(ct_ftp_info->flags[dir] & NF_CT_FTP_SEQ_PICKUP)) {
ct_ftp_info->flags[dir] ^= NF_CT_FTP_SEQ_PICKUP;
goto skip_nl_seq;
}

/* Now if this ends in \n, update ftp info. */
pr_debug("nf_conntrack_ftp: wrong seq pos %s(%u) or %s(%u)\n",
ct_ftp_info->seq_aft_nl_num[dir] > 0 ? "" : "(UNSET)",
Expand All @@ -406,6 +412,7 @@ static int help(struct sk_buff *skb,
goto out_update_nl;
}

skip_nl_seq:
/* Initialize IP/IPv6 addr to expected address (it's not mentioned
in EPSV responses) */
cmd.l3num = nf_ct_l3num(ct);
Expand Down Expand Up @@ -512,6 +519,19 @@ static int help(struct sk_buff *skb,
return ret;
}

static int nf_ct_ftp_from_nlattr(struct nlattr *attr, struct nf_conn *ct)
{
struct nf_ct_ftp_master *ftp = nfct_help_data(ct);

/* This conntrack has been injected from user-space, always pick up
* sequence tracking. Otherwise, the first FTP command after the
* failover breaks.
*/
ftp->flags[IP_CT_DIR_ORIGINAL] |= NF_CT_FTP_SEQ_PICKUP;
ftp->flags[IP_CT_DIR_REPLY] |= NF_CT_FTP_SEQ_PICKUP;
return 0;
}

static struct nf_conntrack_helper ftp[MAX_PORTS][2] __read_mostly;

static const struct nf_conntrack_expect_policy ftp_exp_policy = {
Expand Down Expand Up @@ -561,6 +581,7 @@ static int __init nf_conntrack_ftp_init(void)
ftp[i][j].expect_policy = &ftp_exp_policy;
ftp[i][j].me = THIS_MODULE;
ftp[i][j].help = help;
ftp[i][j].from_nlattr = nf_ct_ftp_from_nlattr;
if (ports[i] == FTP_PORT)
sprintf(ftp[i][j].name, "ftp");
else
Expand Down
4 changes: 2 additions & 2 deletions trunk/net/netfilter/nf_conntrack_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ ctnetlink_change_helper(struct nf_conn *ct, const struct nlattr * const cda[])
if (help) {
if (help->helper == helper) {
/* update private helper data if allowed. */
if (helper->from_nlattr && helpinfo)
if (helper->from_nlattr)
helper->from_nlattr(helpinfo, ct);
return 0;
} else
Expand Down Expand Up @@ -1467,7 +1467,7 @@ ctnetlink_create_conntrack(struct net *net, u16 zone,
goto err2;
}
/* set private helper data if allowed. */
if (helper->from_nlattr && helpinfo)
if (helper->from_nlattr)
helper->from_nlattr(helpinfo, ct);

/* not in hash table yet so not strictly necessary */
Expand Down
3 changes: 3 additions & 0 deletions trunk/net/netfilter/nfnetlink_cthelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ nfnl_cthelper_from_nlattr(struct nlattr *attr, struct nf_conn *ct)
{
const struct nf_conn_help *help = nfct_help(ct);

if (attr == NULL)
return -EINVAL;

if (help->helper->data_len == 0)
return -EINVAL;

Expand Down

0 comments on commit bb208fb

Please sign in to comment.