Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 34561
b: refs/heads/master
c: eb2971b
h: refs/heads/master
i:
  34559: e8c2e9d
v: v3
  • Loading branch information
Masahide NAKAMURA authored and David S. Miller committed Sep 22, 2006
1 parent a61de1d commit 7c9fbc7
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 11 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: 6c44e6b7ab500d7e3e3f406c83325671be51a752
refs/heads/master: eb2971b68a7d17a7d0fa2c7fc6fbc4bfe41cd694
1 change: 1 addition & 0 deletions trunk/include/linux/xfrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ enum xfrm_attr_type_t {
XFRMA_REPLAY_VAL,
XFRMA_REPLAY_THRESH,
XFRMA_ETIMER_THRESH,
XFRMA_SRCADDR, /* xfrm_address_t */
__XFRMA_MAX

#define XFRMA_MAX (__XFRMA_MAX - 1)
Expand Down
2 changes: 2 additions & 0 deletions trunk/include/net/xfrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ struct xfrm_state_afinfo {
struct xfrm_tmpl *tmpl,
xfrm_address_t *daddr, xfrm_address_t *saddr);
struct xfrm_state *(*state_lookup)(xfrm_address_t *daddr, u32 spi, u8 proto);
struct xfrm_state *(*state_lookup_byaddr)(xfrm_address_t *daddr, xfrm_address_t *saddr, u8 proto);
struct xfrm_state *(*find_acq)(u8 mode, u32 reqid, u8 proto,
xfrm_address_t *daddr, xfrm_address_t *saddr,
int create);
Expand Down Expand Up @@ -937,6 +938,7 @@ extern void xfrm_state_insert(struct xfrm_state *x);
extern int xfrm_state_add(struct xfrm_state *x);
extern int xfrm_state_update(struct xfrm_state *x);
extern struct xfrm_state *xfrm_state_lookup(xfrm_address_t *daddr, u32 spi, u8 proto, unsigned short family);
extern struct xfrm_state *xfrm_state_lookup_byaddr(xfrm_address_t *daddr, xfrm_address_t *saddr, u8 proto, unsigned short family);
extern struct xfrm_state *xfrm_find_acq_byseq(u32 seq);
extern int xfrm_state_delete(struct xfrm_state *x);
extern void xfrm_state_flush(u8 proto);
Expand Down
9 changes: 9 additions & 0 deletions trunk/net/ipv4/xfrm4_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ __xfrm4_state_lookup(xfrm_address_t *daddr, u32 spi, u8 proto)
return NULL;
}

/* placeholder until ipv4's code is written */
static struct xfrm_state *
__xfrm4_state_lookup_byaddr(xfrm_address_t *daddr, xfrm_address_t *saddr,
u8 proto)
{
return NULL;
}

static struct xfrm_state *
__xfrm4_find_acq(u8 mode, u32 reqid, u8 proto,
xfrm_address_t *daddr, xfrm_address_t *saddr,
Expand Down Expand Up @@ -137,6 +145,7 @@ static struct xfrm_state_afinfo xfrm4_state_afinfo = {
.init_flags = xfrm4_init_flags,
.init_tempsel = __xfrm4_init_tempsel,
.state_lookup = __xfrm4_state_lookup,
.state_lookup_byaddr = __xfrm4_state_lookup_byaddr,
.find_acq = __xfrm4_find_acq,
};

Expand Down
21 changes: 21 additions & 0 deletions trunk/net/ipv6/xfrm6_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@ __xfrm6_init_tempsel(struct xfrm_state *x, struct flowi *fl,
x->props.family = AF_INET6;
}

static struct xfrm_state *
__xfrm6_state_lookup_byaddr(xfrm_address_t *daddr, xfrm_address_t *saddr,
u8 proto)
{
struct xfrm_state *x = NULL;
unsigned h;

h = __xfrm6_src_hash(saddr);
list_for_each_entry(x, xfrm6_state_afinfo.state_bysrc+h, bysrc) {
if (x->props.family == AF_INET6 &&
ipv6_addr_equal((struct in6_addr *)daddr, (struct in6_addr *)x->id.daddr.a6) &&
ipv6_addr_equal((struct in6_addr *)saddr, (struct in6_addr *)x->props.saddr.a6) &&
proto == x->id.proto) {
xfrm_state_hold(x);
return x;
}
}
return NULL;
}

static struct xfrm_state *
__xfrm6_state_lookup(xfrm_address_t *daddr, u32 spi, u8 proto)
{
Expand Down Expand Up @@ -140,6 +160,7 @@ static struct xfrm_state_afinfo xfrm6_state_afinfo = {
.family = AF_INET6,
.init_tempsel = __xfrm6_init_tempsel,
.state_lookup = __xfrm6_state_lookup,
.state_lookup_byaddr = __xfrm6_state_lookup_byaddr,
.find_acq = __xfrm6_find_acq,
};

Expand Down
37 changes: 33 additions & 4 deletions trunk/net/xfrm/xfrm_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,16 @@ void xfrm_state_insert(struct xfrm_state *x)
}
EXPORT_SYMBOL(xfrm_state_insert);

static inline struct xfrm_state *
__xfrm_state_locate(struct xfrm_state_afinfo *afinfo, struct xfrm_state *x,
int use_spi)
{
if (use_spi)
return afinfo->state_lookup(&x->id.daddr, x->id.spi, x->id.proto);
else
return afinfo->state_lookup_byaddr(&x->id.daddr, &x->props.saddr, x->id.proto);
}

static struct xfrm_state *__xfrm_find_acq_byseq(u32 seq);

int xfrm_state_add(struct xfrm_state *x)
Expand All @@ -495,6 +505,7 @@ int xfrm_state_add(struct xfrm_state *x)
struct xfrm_state *x1;
int family;
int err;
int use_spi = xfrm_id_proto_match(x->id.proto, IPSEC_PROTO_ANY);

family = x->props.family;
afinfo = xfrm_state_get_afinfo(family);
Expand All @@ -503,23 +514,23 @@ int xfrm_state_add(struct xfrm_state *x)

spin_lock_bh(&xfrm_state_lock);

x1 = afinfo->state_lookup(&x->id.daddr, x->id.spi, x->id.proto);
x1 = __xfrm_state_locate(afinfo, x, use_spi);
if (x1) {
xfrm_state_put(x1);
x1 = NULL;
err = -EEXIST;
goto out;
}

if (x->km.seq) {
if (use_spi && x->km.seq) {
x1 = __xfrm_find_acq_byseq(x->km.seq);
if (x1 && xfrm_addr_cmp(&x1->id.daddr, &x->id.daddr, family)) {
xfrm_state_put(x1);
x1 = NULL;
}
}

if (!x1)
if (use_spi && !x1)
x1 = afinfo->find_acq(
x->props.mode, x->props.reqid, x->id.proto,
&x->id.daddr, &x->props.saddr, 0);
Expand Down Expand Up @@ -548,13 +559,14 @@ int xfrm_state_update(struct xfrm_state *x)
struct xfrm_state_afinfo *afinfo;
struct xfrm_state *x1;
int err;
int use_spi = xfrm_id_proto_match(x->id.proto, IPSEC_PROTO_ANY);

afinfo = xfrm_state_get_afinfo(x->props.family);
if (unlikely(afinfo == NULL))
return -EAFNOSUPPORT;

spin_lock_bh(&xfrm_state_lock);
x1 = afinfo->state_lookup(&x->id.daddr, x->id.spi, x->id.proto);
x1 = __xfrm_state_locate(afinfo, x, use_spi);

err = -ESRCH;
if (!x1)
Expand Down Expand Up @@ -674,6 +686,23 @@ xfrm_state_lookup(xfrm_address_t *daddr, u32 spi, u8 proto,
}
EXPORT_SYMBOL(xfrm_state_lookup);

struct xfrm_state *
xfrm_state_lookup_byaddr(xfrm_address_t *daddr, xfrm_address_t *saddr,
u8 proto, unsigned short family)
{
struct xfrm_state *x;
struct xfrm_state_afinfo *afinfo = xfrm_state_get_afinfo(family);
if (!afinfo)
return NULL;

spin_lock_bh(&xfrm_state_lock);
x = afinfo->state_lookup_byaddr(daddr, saddr, proto);
spin_unlock_bh(&xfrm_state_lock);
xfrm_state_put_afinfo(afinfo);
return x;
}
EXPORT_SYMBOL(xfrm_state_lookup_byaddr);

struct xfrm_state *
xfrm_find_acq(u8 mode, u32 reqid, u8 proto,
xfrm_address_t *daddr, xfrm_address_t *saddr,
Expand Down
59 changes: 53 additions & 6 deletions trunk/net/xfrm/xfrm_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ static int verify_encap_tmpl(struct rtattr **xfrma)
return 0;
}

static int verify_one_addr(struct rtattr **xfrma, enum xfrm_attr_type_t type,
xfrm_address_t **addrp)
{
struct rtattr *rt = xfrma[type - 1];

if (!rt)
return 0;

if ((rt->rta_len - sizeof(*rt)) < sizeof(**addrp))
return -EINVAL;

if (addrp)
*addrp = RTA_DATA(rt);

return 0;
}

static inline int verify_sec_ctx_len(struct rtattr **xfrma)
{
Expand Down Expand Up @@ -418,16 +434,48 @@ static int xfrm_add_sa(struct sk_buff *skb, struct nlmsghdr *nlh, void **xfrma)
return err;
}

static struct xfrm_state *xfrm_user_state_lookup(struct xfrm_usersa_id *p,
struct rtattr **xfrma,
int *errp)
{
struct xfrm_state *x = NULL;
int err;

if (xfrm_id_proto_match(p->proto, IPSEC_PROTO_ANY)) {
err = -ESRCH;
x = xfrm_state_lookup(&p->daddr, p->spi, p->proto, p->family);
} else {
xfrm_address_t *saddr = NULL;

err = verify_one_addr(xfrma, XFRMA_SRCADDR, &saddr);
if (err)
goto out;

if (!saddr) {
err = -EINVAL;
goto out;
}

x = xfrm_state_lookup_byaddr(&p->daddr, saddr, p->proto,
p->family);
}

out:
if (!x && errp)
*errp = err;
return x;
}

static int xfrm_del_sa(struct sk_buff *skb, struct nlmsghdr *nlh, void **xfrma)
{
struct xfrm_state *x;
int err;
int err = -ESRCH;
struct km_event c;
struct xfrm_usersa_id *p = NLMSG_DATA(nlh);

x = xfrm_state_lookup(&p->daddr, p->spi, p->proto, p->family);
x = xfrm_user_state_lookup(p, (struct rtattr **)xfrma, &err);
if (x == NULL)
return -ESRCH;
return err;

if ((err = security_xfrm_state_delete(x)) != 0)
goto out;
Expand Down Expand Up @@ -578,10 +626,9 @@ static int xfrm_get_sa(struct sk_buff *skb, struct nlmsghdr *nlh, void **xfrma)
struct xfrm_usersa_id *p = NLMSG_DATA(nlh);
struct xfrm_state *x;
struct sk_buff *resp_skb;
int err;
int err = -ESRCH;

x = xfrm_state_lookup(&p->daddr, p->spi, p->proto, p->family);
err = -ESRCH;
x = xfrm_user_state_lookup(p, (struct rtattr **)xfrma, &err);
if (x == NULL)
goto out_noput;

Expand Down

0 comments on commit 7c9fbc7

Please sign in to comment.