[PATCH 42/44] [XFRM] POLICY: Support netlink socket interface for sub policy.

2006-08-23 Thread YOSHIFUJI Hideaki
From: Masahide NAKAMURA [EMAIL PROTECTED]

Sub policy can be used through netlink socket.
PF_KEY uses main only and it is TODO to support sub.

Signed-off-by: Masahide NAKAMURA [EMAIL PROTECTED]
Signed-off-by: YOSHIFUJI Hideaki [EMAIL PROTECTED]
---
 include/linux/xfrm.h |7 +++
 include/net/xfrm.h   |1 
 net/key/af_key.c |   18 +--
 net/xfrm/xfrm_user.c |  134 +-
 4 files changed, 142 insertions(+), 18 deletions(-)

diff --git a/include/linux/xfrm.h b/include/linux/xfrm.h
index 492fb98..14ecd19 100644
--- a/include/linux/xfrm.h
+++ b/include/linux/xfrm.h
@@ -230,6 +230,12 @@ enum xfrm_ae_ftype_t {
 #define XFRM_AE_MAX (__XFRM_AE_MAX - 1)
 };
 
+struct xfrm_userpolicy_type {
+   __u8type;
+   __u16   reserved1;
+   __u8reserved2;
+};
+
 /* Netlink message attributes.  */
 enum xfrm_attr_type_t {
XFRMA_UNSPEC,
@@ -248,6 +254,7 @@ enum xfrm_attr_type_t {
XFRMA_SRCADDR,  /* xfrm_address_t */
XFRMA_COADDR,   /* xfrm_address_t */
XFRMA_LASTUSED,
+   XFRMA_POLICY_TYPE,  /* struct xfrm_userpolicy_type */
__XFRMA_MAX
 
 #define XFRMA_MAX (__XFRMA_MAX - 1)
diff --git a/include/net/xfrm.h b/include/net/xfrm.h
index aab31a2..0f1117d 100644
--- a/include/net/xfrm.h
+++ b/include/net/xfrm.h
@@ -204,6 +204,7 @@ struct km_event
u32 proto;
u32 byid;
u32 aevent;
+   u32 type;
} data;
 
u32 seq;
diff --git a/net/key/af_key.c b/net/key/af_key.c
index 19e047b..83b443d 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -1731,7 +1731,8 @@ static u32 gen_reqid(void)
++reqid;
if (reqid == 0)
reqid = IPSEC_MANUAL_REQID_MAX+1;
-   if (xfrm_policy_walk(check_reqid, (void*)reqid) != -EEXIST)
+   if (xfrm_policy_walk(XFRM_POLICY_TYPE_MAIN, check_reqid,
+(void*)reqid) != -EEXIST)
return reqid;
} while (reqid != start);
return 0;
@@ -2268,7 +2269,8 @@ static int pfkey_spddelete(struct sock *
return err;
}
 
-   xp = xfrm_policy_bysel_ctx(pol-sadb_x_policy_dir-1, sel, 
tmp.security, 1);
+   xp = xfrm_policy_bysel_ctx(XFRM_POLICY_TYPE_MAIN, 
pol-sadb_x_policy_dir-1,
+  sel, tmp.security, 1);
security_xfrm_policy_free(tmp);
if (xp == NULL)
return -ENOENT;
@@ -2330,7 +2332,7 @@ static int pfkey_spdget(struct sock *sk,
if (dir = XFRM_POLICY_MAX)
return -EINVAL;
 
-   xp = xfrm_policy_byid(dir, pol-sadb_x_policy_id,
+   xp = xfrm_policy_byid(XFRM_POLICY_TYPE_MAIN, dir, pol-sadb_x_policy_id,
  hdr-sadb_msg_type == SADB_X_SPDDELETE2);
if (xp == NULL)
return -ENOENT;
@@ -2378,7 +2380,7 @@ static int pfkey_spddump(struct sock *sk
 {
struct pfkey_dump_data data = { .skb = skb, .hdr = hdr, .sk = sk };
 
-   return xfrm_policy_walk(dump_sp, data);
+   return xfrm_policy_walk(XFRM_POLICY_TYPE_MAIN, dump_sp, data);
 }
 
 static int key_notify_policy_flush(struct km_event *c)
@@ -2405,7 +2407,8 @@ static int pfkey_spdflush(struct sock *s
 {
struct km_event c;
 
-   xfrm_policy_flush();
+   xfrm_policy_flush(XFRM_POLICY_TYPE_MAIN);
+   c.data.type = XFRM_POLICY_TYPE_MAIN;
c.event = XFRM_MSG_FLUSHPOLICY;
c.pid = hdr-sadb_msg_pid;
c.seq = hdr-sadb_msg_seq;
@@ -2667,6 +2670,9 @@ static int pfkey_send_notify(struct xfrm
 
 static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, struct 
km_event *c)
 {
+   if (xp  xp-type != XFRM_POLICY_TYPE_MAIN)
+   return 0;
+
switch (c-event) {
case XFRM_MSG_POLEXPIRE:
return key_notify_policy_expire(xp, c);
@@ -2675,6 +2681,8 @@ static int pfkey_send_policy_notify(stru
case XFRM_MSG_UPDPOLICY:
return key_notify_policy(xp, dir, c);
case XFRM_MSG_FLUSHPOLICY:
+   if (c-data.type != XFRM_POLICY_TYPE_MAIN)
+   break;
return key_notify_policy_flush(c);
default:
printk(pfkey: Unknown policy event %d\n, c-event);
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index a4a4dd6..a096586 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -784,6 +784,22 @@ static int verify_policy_dir(__u8 dir)
return 0;
 }
 
+static int verify_policy_type(__u8 type)
+{
+   switch (type) {
+   case XFRM_POLICY_TYPE_MAIN:
+#ifdef CONFIG_XFRM_SUB_POLICY
+   case XFRM_POLICY_TYPE_SUB:
+#endif
+   break;
+
+   default:
+   return -EINVAL;
+   };
+
+   return 0;
+}
+
 static int verify_newpolicy_info(struct xfrm_userpolicy_info *p)
 {
switch (p-share) {
@@ 

Re: [PATCH 42/44] [XFRM] POLICY: Support netlink socket interface for sub policy.

2006-08-23 Thread David Miller
From: YOSHIFUJI Hideaki [EMAIL PROTECTED]
Date: Thu, 24 Aug 2006 00:02:43 +0900

 Sub policy can be used through netlink socket.
 PF_KEY uses main only and it is TODO to support sub.
 
 Signed-off-by: Masahide NAKAMURA [EMAIL PROTECTED]
 Signed-off-by: YOSHIFUJI Hideaki [EMAIL PROTECTED]

Applied to net-2.6.19, thanks a lot.
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html