Skip to content

Commit 980ebd2

Browse files
Jamal Hadi Salimdavem330
authored andcommitted
[IPSEC]: Sync series - acquire insert
This introduces a feature similar to the one described in RFC 2367: " ... the application needing an SA sends a PF_KEY SADB_ACQUIRE message down to the Key Engine, which then either returns an error or sends a similar SADB_ACQUIRE message up to one or more key management applications capable of creating such SAs. ... ... The third is where an application-layer consumer of security associations (e.g. an OSPFv2 or RIPv2 daemon) needs a security association. Send an SADB_ACQUIRE message from a user process to the kernel. <base, address(SD), (address(P),) (identity(SD),) (sensitivity,) proposal> The kernel returns an SADB_ACQUIRE message to registered sockets. <base, address(SD), (address(P),) (identity(SD),) (sensitivity,) proposal> The user-level consumer waits for an SADB_UPDATE or SADB_ADD message for its particular type, and then can use that association by using SADB_GET messages. " An app such as OSPF could then use ipsec KM to get keys Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent d51d081 commit 980ebd2

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

include/net/xfrm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,10 @@ extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
214214
extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
215215
extern void km_policy_notify(struct xfrm_policy *xp, int dir, struct km_event *c);
216216
extern void km_state_notify(struct xfrm_state *x, struct km_event *c);
217-
218217
#define XFRM_ACQ_EXPIRES 30
219218

220219
struct xfrm_tmpl;
220+
extern int km_query(struct xfrm_state *x, struct xfrm_tmpl *t, struct xfrm_policy *pol);
221221
struct xfrm_state_afinfo {
222222
unsigned short family;
223223
rwlock_t lock;

net/xfrm/xfrm_state.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static int __xfrm_state_delete(struct xfrm_state *x);
5757
static struct xfrm_state_afinfo *xfrm_state_get_afinfo(unsigned short family);
5858
static void xfrm_state_put_afinfo(struct xfrm_state_afinfo *afinfo);
5959

60-
static int km_query(struct xfrm_state *x, struct xfrm_tmpl *t, struct xfrm_policy *pol);
60+
int km_query(struct xfrm_state *x, struct xfrm_tmpl *t, struct xfrm_policy *pol);
6161
static void km_state_expired(struct xfrm_state *x, int hard);
6262

6363
static void xfrm_state_gc_destroy(struct xfrm_state *x)
@@ -925,7 +925,7 @@ void km_state_expired(struct xfrm_state *x, int hard)
925925
* We send to all registered managers regardless of failure
926926
* We are happy with one success
927927
*/
928-
static int km_query(struct xfrm_state *x, struct xfrm_tmpl *t, struct xfrm_policy *pol)
928+
int km_query(struct xfrm_state *x, struct xfrm_tmpl *t, struct xfrm_policy *pol)
929929
{
930930
int err = -EINVAL, acqret;
931931
struct xfrm_mgr *km;
@@ -939,6 +939,7 @@ static int km_query(struct xfrm_state *x, struct xfrm_tmpl *t, struct xfrm_polic
939939
read_unlock(&xfrm_km_lock);
940940
return err;
941941
}
942+
EXPORT_SYMBOL(km_query);
942943

943944
int km_new_mapping(struct xfrm_state *x, xfrm_address_t *ipaddr, u16 sport)
944945
{

net/xfrm/xfrm_user.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,58 @@ static int xfrm_flush_policy(struct sk_buff *skb, struct nlmsghdr *nlh, void **x
12321232
return 0;
12331233
}
12341234

1235+
static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh, void **xfrma)
1236+
{
1237+
struct xfrm_policy *xp;
1238+
struct xfrm_user_tmpl *ut;
1239+
int i;
1240+
struct rtattr *rt = xfrma[XFRMA_TMPL-1];
1241+
1242+
struct xfrm_user_acquire *ua = NLMSG_DATA(nlh);
1243+
struct xfrm_state *x = xfrm_state_alloc();
1244+
int err = -ENOMEM;
1245+
1246+
if (!x)
1247+
return err;
1248+
1249+
err = verify_newpolicy_info(&ua->policy);
1250+
if (err) {
1251+
printk("BAD policy passed\n");
1252+
kfree(x);
1253+
return err;
1254+
}
1255+
1256+
/* build an XP */
1257+
xp = xfrm_policy_construct(&ua->policy, (struct rtattr **) xfrma, &err); if (!xp) {
1258+
kfree(x);
1259+
return err;
1260+
}
1261+
1262+
memcpy(&x->id, &ua->id, sizeof(ua->id));
1263+
memcpy(&x->props.saddr, &ua->saddr, sizeof(ua->saddr));
1264+
memcpy(&x->sel, &ua->sel, sizeof(ua->sel));
1265+
1266+
ut = RTA_DATA(rt);
1267+
/* extract the templates and for each call km_key */
1268+
for (i = 0; i < xp->xfrm_nr; i++, ut++) {
1269+
struct xfrm_tmpl *t = &xp->xfrm_vec[i];
1270+
memcpy(&x->id, &t->id, sizeof(x->id));
1271+
x->props.mode = t->mode;
1272+
x->props.reqid = t->reqid;
1273+
x->props.family = ut->family;
1274+
t->aalgos = ua->aalgos;
1275+
t->ealgos = ua->ealgos;
1276+
t->calgos = ua->calgos;
1277+
err = km_query(x, t, xp);
1278+
1279+
}
1280+
1281+
kfree(x);
1282+
kfree(xp);
1283+
1284+
return 0;
1285+
}
1286+
12351287

12361288
#define XMSGSIZE(type) NLMSG_LENGTH(sizeof(struct type))
12371289

@@ -1243,6 +1295,7 @@ static const int xfrm_msg_min[XFRM_NR_MSGTYPES] = {
12431295
[XFRM_MSG_DELPOLICY - XFRM_MSG_BASE] = XMSGSIZE(xfrm_userpolicy_id),
12441296
[XFRM_MSG_GETPOLICY - XFRM_MSG_BASE] = XMSGSIZE(xfrm_userpolicy_id),
12451297
[XFRM_MSG_ALLOCSPI - XFRM_MSG_BASE] = XMSGSIZE(xfrm_userspi_info),
1298+
[XFRM_MSG_ACQUIRE - XFRM_MSG_BASE] = XMSGSIZE(xfrm_user_acquire),
12461299
[XFRM_MSG_UPDPOLICY - XFRM_MSG_BASE] = XMSGSIZE(xfrm_userpolicy_info),
12471300
[XFRM_MSG_UPDSA - XFRM_MSG_BASE] = XMSGSIZE(xfrm_usersa_info),
12481301
[XFRM_MSG_FLUSHSA - XFRM_MSG_BASE] = XMSGSIZE(xfrm_usersa_flush),
@@ -1266,6 +1319,7 @@ static struct xfrm_link {
12661319
[XFRM_MSG_GETPOLICY - XFRM_MSG_BASE] = { .doit = xfrm_get_policy,
12671320
.dump = xfrm_dump_policy },
12681321
[XFRM_MSG_ALLOCSPI - XFRM_MSG_BASE] = { .doit = xfrm_alloc_userspi },
1322+
[XFRM_MSG_ACQUIRE - XFRM_MSG_BASE] = { .doit = xfrm_add_acquire },
12691323
[XFRM_MSG_UPDPOLICY - XFRM_MSG_BASE] = { .doit = xfrm_add_policy },
12701324
[XFRM_MSG_UPDSA - XFRM_MSG_BASE] = { .doit = xfrm_add_sa },
12711325
[XFRM_MSG_FLUSHSA - XFRM_MSG_BASE] = { .doit = xfrm_flush_sa },

0 commit comments

Comments
 (0)