forked from mirrors/linux
		
	[XFRM]: Introduce XFRM_MSG_REPORT.
XFRM_MSG_REPORT is a message as notification of state protocol and selector from kernel to user-space. Mobile IPv6 will use it when inbound reject is occurred at route optimization to make user-space know a binding error requirement. Based on MIPL2 kernel patch. Signed-off-by: Masahide NAKAMURA <nakam@linux-ipv6.org> Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
		
							parent
							
								
									df0ba92a99
								
							
						
					
					
						commit
						97a64b4577
					
				
					 4 changed files with 79 additions and 0 deletions
				
			
		| 
						 | 
					@ -166,6 +166,10 @@ enum {
 | 
				
			||||||
#define XFRM_MSG_NEWAE XFRM_MSG_NEWAE
 | 
					#define XFRM_MSG_NEWAE XFRM_MSG_NEWAE
 | 
				
			||||||
	XFRM_MSG_GETAE,
 | 
						XFRM_MSG_GETAE,
 | 
				
			||||||
#define XFRM_MSG_GETAE XFRM_MSG_GETAE
 | 
					#define XFRM_MSG_GETAE XFRM_MSG_GETAE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						XFRM_MSG_REPORT,
 | 
				
			||||||
 | 
					#define XFRM_MSG_REPORT XFRM_MSG_REPORT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	__XFRM_MSG_MAX
 | 
						__XFRM_MSG_MAX
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
#define XFRM_MSG_MAX (__XFRM_MSG_MAX - 1)
 | 
					#define XFRM_MSG_MAX (__XFRM_MSG_MAX - 1)
 | 
				
			||||||
| 
						 | 
					@ -325,12 +329,18 @@ struct xfrm_usersa_flush {
 | 
				
			||||||
	__u8				proto;
 | 
						__u8				proto;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct xfrm_user_report {
 | 
				
			||||||
 | 
						__u8				proto;
 | 
				
			||||||
 | 
						struct xfrm_selector		sel;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifndef __KERNEL__
 | 
					#ifndef __KERNEL__
 | 
				
			||||||
/* backwards compatibility for userspace */
 | 
					/* backwards compatibility for userspace */
 | 
				
			||||||
#define XFRMGRP_ACQUIRE		1
 | 
					#define XFRMGRP_ACQUIRE		1
 | 
				
			||||||
#define XFRMGRP_EXPIRE		2
 | 
					#define XFRMGRP_EXPIRE		2
 | 
				
			||||||
#define XFRMGRP_SA		4
 | 
					#define XFRMGRP_SA		4
 | 
				
			||||||
#define XFRMGRP_POLICY		8
 | 
					#define XFRMGRP_POLICY		8
 | 
				
			||||||
 | 
					#define XFRMGRP_REPORT		0x10
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum xfrm_nlgroups {
 | 
					enum xfrm_nlgroups {
 | 
				
			||||||
| 
						 | 
					@ -346,6 +356,8 @@ enum xfrm_nlgroups {
 | 
				
			||||||
#define XFRMNLGRP_POLICY	XFRMNLGRP_POLICY
 | 
					#define XFRMNLGRP_POLICY	XFRMNLGRP_POLICY
 | 
				
			||||||
	XFRMNLGRP_AEVENTS,
 | 
						XFRMNLGRP_AEVENTS,
 | 
				
			||||||
#define XFRMNLGRP_AEVENTS	XFRMNLGRP_AEVENTS
 | 
					#define XFRMNLGRP_AEVENTS	XFRMNLGRP_AEVENTS
 | 
				
			||||||
 | 
						XFRMNLGRP_REPORT,
 | 
				
			||||||
 | 
					#define XFRMNLGRP_REPORT	XFRMNLGRP_REPORT
 | 
				
			||||||
	__XFRMNLGRP_MAX
 | 
						__XFRMNLGRP_MAX
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
#define XFRMNLGRP_MAX	(__XFRMNLGRP_MAX - 1)
 | 
					#define XFRMNLGRP_MAX	(__XFRMNLGRP_MAX - 1)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -381,6 +381,7 @@ struct xfrm_mgr
 | 
				
			||||||
	struct xfrm_policy	*(*compile_policy)(struct sock *sk, int opt, u8 *data, int len, int *dir);
 | 
						struct xfrm_policy	*(*compile_policy)(struct sock *sk, int opt, u8 *data, int len, int *dir);
 | 
				
			||||||
	int			(*new_mapping)(struct xfrm_state *x, xfrm_address_t *ipaddr, u16 sport);
 | 
						int			(*new_mapping)(struct xfrm_state *x, xfrm_address_t *ipaddr, u16 sport);
 | 
				
			||||||
	int			(*notify_policy)(struct xfrm_policy *x, int dir, struct km_event *c);
 | 
						int			(*notify_policy)(struct xfrm_policy *x, int dir, struct km_event *c);
 | 
				
			||||||
 | 
						int			(*report)(u8 proto, struct xfrm_selector *sel, xfrm_address_t *addr);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern int xfrm_register_km(struct xfrm_mgr *km);
 | 
					extern int xfrm_register_km(struct xfrm_mgr *km);
 | 
				
			||||||
| 
						 | 
					@ -1043,6 +1044,7 @@ extern void xfrm_init_pmtu(struct dst_entry *dst);
 | 
				
			||||||
extern wait_queue_head_t km_waitq;
 | 
					extern wait_queue_head_t km_waitq;
 | 
				
			||||||
extern int km_new_mapping(struct xfrm_state *x, xfrm_address_t *ipaddr, u16 sport);
 | 
					extern int km_new_mapping(struct xfrm_state *x, xfrm_address_t *ipaddr, u16 sport);
 | 
				
			||||||
extern void km_policy_expired(struct xfrm_policy *pol, int dir, int hard, u32 pid);
 | 
					extern void km_policy_expired(struct xfrm_policy *pol, int dir, int hard, u32 pid);
 | 
				
			||||||
 | 
					extern int km_report(u8 proto, struct xfrm_selector *sel, xfrm_address_t *addr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern void xfrm_input_init(void);
 | 
					extern void xfrm_input_init(void);
 | 
				
			||||||
extern int xfrm_parse_spi(struct sk_buff *skb, u8 nexthdr, u32 *spi, u32 *seq);
 | 
					extern int xfrm_parse_spi(struct sk_buff *skb, u8 nexthdr, u32 *spi, u32 *seq);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1055,6 +1055,25 @@ void km_policy_expired(struct xfrm_policy *pol, int dir, int hard, u32 pid)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
EXPORT_SYMBOL(km_policy_expired);
 | 
					EXPORT_SYMBOL(km_policy_expired);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int km_report(u8 proto, struct xfrm_selector *sel, xfrm_address_t *addr)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int err = -EINVAL;
 | 
				
			||||||
 | 
						int ret;
 | 
				
			||||||
 | 
						struct xfrm_mgr *km;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						read_lock(&xfrm_km_lock);
 | 
				
			||||||
 | 
						list_for_each_entry(km, &xfrm_km_list, list) {
 | 
				
			||||||
 | 
							if (km->report) {
 | 
				
			||||||
 | 
								ret = km->report(proto, sel, addr);
 | 
				
			||||||
 | 
								if (!ret)
 | 
				
			||||||
 | 
									err = ret;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						read_unlock(&xfrm_km_lock);
 | 
				
			||||||
 | 
						return err;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					EXPORT_SYMBOL(km_report);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen)
 | 
					int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int err;
 | 
						int err;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1491,6 +1491,7 @@ static const int xfrm_msg_min[XFRM_NR_MSGTYPES] = {
 | 
				
			||||||
	[XFRM_MSG_FLUSHPOLICY - XFRM_MSG_BASE] = NLMSG_LENGTH(0),
 | 
						[XFRM_MSG_FLUSHPOLICY - XFRM_MSG_BASE] = NLMSG_LENGTH(0),
 | 
				
			||||||
	[XFRM_MSG_NEWAE       - XFRM_MSG_BASE] = XMSGSIZE(xfrm_aevent_id),
 | 
						[XFRM_MSG_NEWAE       - XFRM_MSG_BASE] = XMSGSIZE(xfrm_aevent_id),
 | 
				
			||||||
	[XFRM_MSG_GETAE       - XFRM_MSG_BASE] = XMSGSIZE(xfrm_aevent_id),
 | 
						[XFRM_MSG_GETAE       - XFRM_MSG_BASE] = XMSGSIZE(xfrm_aevent_id),
 | 
				
			||||||
 | 
						[XFRM_MSG_REPORT      - XFRM_MSG_BASE] = XMSGSIZE(xfrm_user_report),
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#undef XMSGSIZE
 | 
					#undef XMSGSIZE
 | 
				
			||||||
| 
						 | 
					@ -2058,12 +2059,57 @@ static int xfrm_send_policy_notify(struct xfrm_policy *xp, int dir, struct km_ev
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int build_report(struct sk_buff *skb, u8 proto,
 | 
				
			||||||
 | 
								struct xfrm_selector *sel, xfrm_address_t *addr)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct xfrm_user_report *ur;
 | 
				
			||||||
 | 
						struct nlmsghdr *nlh;
 | 
				
			||||||
 | 
						unsigned char *b = skb->tail;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						nlh = NLMSG_PUT(skb, 0, 0, XFRM_MSG_REPORT, sizeof(*ur));
 | 
				
			||||||
 | 
						ur = NLMSG_DATA(nlh);
 | 
				
			||||||
 | 
						nlh->nlmsg_flags = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ur->proto = proto;
 | 
				
			||||||
 | 
						memcpy(&ur->sel, sel, sizeof(ur->sel));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (addr)
 | 
				
			||||||
 | 
							RTA_PUT(skb, XFRMA_COADDR, sizeof(*addr), addr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						nlh->nlmsg_len = skb->tail - b;
 | 
				
			||||||
 | 
						return skb->len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					nlmsg_failure:
 | 
				
			||||||
 | 
					rtattr_failure:
 | 
				
			||||||
 | 
						skb_trim(skb, b - skb->data);
 | 
				
			||||||
 | 
						return -1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int xfrm_send_report(u8 proto, struct xfrm_selector *sel,
 | 
				
			||||||
 | 
								    xfrm_address_t *addr)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct sk_buff *skb;
 | 
				
			||||||
 | 
						size_t len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						len = NLMSG_ALIGN(NLMSG_LENGTH(sizeof(struct xfrm_user_report)));
 | 
				
			||||||
 | 
						skb = alloc_skb(len, GFP_ATOMIC);
 | 
				
			||||||
 | 
						if (skb == NULL)
 | 
				
			||||||
 | 
							return -ENOMEM;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (build_report(skb, proto, sel, addr) < 0)
 | 
				
			||||||
 | 
							BUG();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						NETLINK_CB(skb).dst_group = XFRMNLGRP_REPORT;
 | 
				
			||||||
 | 
						return netlink_broadcast(xfrm_nl, skb, 0, XFRMNLGRP_REPORT, GFP_ATOMIC);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct xfrm_mgr netlink_mgr = {
 | 
					static struct xfrm_mgr netlink_mgr = {
 | 
				
			||||||
	.id		= "netlink",
 | 
						.id		= "netlink",
 | 
				
			||||||
	.notify		= xfrm_send_state_notify,
 | 
						.notify		= xfrm_send_state_notify,
 | 
				
			||||||
	.acquire	= xfrm_send_acquire,
 | 
						.acquire	= xfrm_send_acquire,
 | 
				
			||||||
	.compile_policy	= xfrm_compile_policy,
 | 
						.compile_policy	= xfrm_compile_policy,
 | 
				
			||||||
	.notify_policy	= xfrm_send_policy_notify,
 | 
						.notify_policy	= xfrm_send_policy_notify,
 | 
				
			||||||
 | 
						.report		= xfrm_send_report,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int __init xfrm_user_init(void)
 | 
					static int __init xfrm_user_init(void)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue