Commit 4c93fbb0 authored by David S. Miller's avatar David S. Miller

pfkey: Use const where possible.

This actually pointed out a (seemingly known) bug where we mangle the
pfkey header in a potentially shared SKB, which is fixed here.
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 52bc9747
...@@ -70,7 +70,7 @@ static inline struct pfkey_sock *pfkey_sk(struct sock *sk) ...@@ -70,7 +70,7 @@ static inline struct pfkey_sock *pfkey_sk(struct sock *sk)
return (struct pfkey_sock *)sk; return (struct pfkey_sock *)sk;
} }
static int pfkey_can_dump(struct sock *sk) static int pfkey_can_dump(const struct sock *sk)
{ {
if (3 * atomic_read(&sk->sk_rmem_alloc) <= 2 * sk->sk_rcvbuf) if (3 * atomic_read(&sk->sk_rmem_alloc) <= 2 * sk->sk_rcvbuf)
return 1; return 1;
...@@ -303,12 +303,13 @@ static int pfkey_do_dump(struct pfkey_sock *pfk) ...@@ -303,12 +303,13 @@ static int pfkey_do_dump(struct pfkey_sock *pfk)
return rc; return rc;
} }
static inline void pfkey_hdr_dup(struct sadb_msg *new, struct sadb_msg *orig) static inline void pfkey_hdr_dup(struct sadb_msg *new,
const struct sadb_msg *orig)
{ {
*new = *orig; *new = *orig;
} }
static int pfkey_error(struct sadb_msg *orig, int err, struct sock *sk) static int pfkey_error(const struct sadb_msg *orig, int err, struct sock *sk)
{ {
struct sk_buff *skb = alloc_skb(sizeof(struct sadb_msg) + 16, GFP_KERNEL); struct sk_buff *skb = alloc_skb(sizeof(struct sadb_msg) + 16, GFP_KERNEL);
struct sadb_msg *hdr; struct sadb_msg *hdr;
...@@ -369,13 +370,13 @@ static u8 sadb_ext_min_len[] = { ...@@ -369,13 +370,13 @@ static u8 sadb_ext_min_len[] = {
}; };
/* Verify sadb_address_{len,prefixlen} against sa_family. */ /* Verify sadb_address_{len,prefixlen} against sa_family. */
static int verify_address_len(void *p) static int verify_address_len(const void *p)
{ {
struct sadb_address *sp = p; const struct sadb_address *sp = p;
struct sockaddr *addr = (struct sockaddr *)(sp + 1); const struct sockaddr *addr = (const struct sockaddr *)(sp + 1);
struct sockaddr_in *sin; const struct sockaddr_in *sin;
#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
struct sockaddr_in6 *sin6; const struct sockaddr_in6 *sin6;
#endif #endif
int len; int len;
...@@ -411,16 +412,16 @@ static int verify_address_len(void *p) ...@@ -411,16 +412,16 @@ static int verify_address_len(void *p)
return 0; return 0;
} }
static inline int pfkey_sec_ctx_len(struct sadb_x_sec_ctx *sec_ctx) static inline int pfkey_sec_ctx_len(const struct sadb_x_sec_ctx *sec_ctx)
{ {
return DIV_ROUND_UP(sizeof(struct sadb_x_sec_ctx) + return DIV_ROUND_UP(sizeof(struct sadb_x_sec_ctx) +
sec_ctx->sadb_x_ctx_len, sec_ctx->sadb_x_ctx_len,
sizeof(uint64_t)); sizeof(uint64_t));
} }
static inline int verify_sec_ctx_len(void *p) static inline int verify_sec_ctx_len(const void *p)
{ {
struct sadb_x_sec_ctx *sec_ctx = (struct sadb_x_sec_ctx *)p; const struct sadb_x_sec_ctx *sec_ctx = p;
int len = sec_ctx->sadb_x_ctx_len; int len = sec_ctx->sadb_x_ctx_len;
if (len > PAGE_SIZE) if (len > PAGE_SIZE)
...@@ -434,7 +435,7 @@ static inline int verify_sec_ctx_len(void *p) ...@@ -434,7 +435,7 @@ static inline int verify_sec_ctx_len(void *p)
return 0; return 0;
} }
static inline struct xfrm_user_sec_ctx *pfkey_sadb2xfrm_user_sec_ctx(struct sadb_x_sec_ctx *sec_ctx) static inline struct xfrm_user_sec_ctx *pfkey_sadb2xfrm_user_sec_ctx(const struct sadb_x_sec_ctx *sec_ctx)
{ {
struct xfrm_user_sec_ctx *uctx = NULL; struct xfrm_user_sec_ctx *uctx = NULL;
int ctx_size = sec_ctx->sadb_x_ctx_len; int ctx_size = sec_ctx->sadb_x_ctx_len;
...@@ -455,16 +456,16 @@ static inline struct xfrm_user_sec_ctx *pfkey_sadb2xfrm_user_sec_ctx(struct sadb ...@@ -455,16 +456,16 @@ static inline struct xfrm_user_sec_ctx *pfkey_sadb2xfrm_user_sec_ctx(struct sadb
return uctx; return uctx;
} }
static int present_and_same_family(struct sadb_address *src, static int present_and_same_family(const struct sadb_address *src,
struct sadb_address *dst) const struct sadb_address *dst)
{ {
struct sockaddr *s_addr, *d_addr; const struct sockaddr *s_addr, *d_addr;
if (!src || !dst) if (!src || !dst)
return 0; return 0;
s_addr = (struct sockaddr *)(src + 1); s_addr = (const struct sockaddr *)(src + 1);
d_addr = (struct sockaddr *)(dst + 1); d_addr = (const struct sockaddr *)(dst + 1);
if (s_addr->sa_family != d_addr->sa_family) if (s_addr->sa_family != d_addr->sa_family)
return 0; return 0;
if (s_addr->sa_family != AF_INET if (s_addr->sa_family != AF_INET
...@@ -477,15 +478,15 @@ static int present_and_same_family(struct sadb_address *src, ...@@ -477,15 +478,15 @@ static int present_and_same_family(struct sadb_address *src,
return 1; return 1;
} }
static int parse_exthdrs(struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs) static int parse_exthdrs(struct sk_buff *skb, const struct sadb_msg *hdr, void **ext_hdrs)
{ {
char *p = (char *) hdr; const char *p = (char *) hdr;
int len = skb->len; int len = skb->len;
len -= sizeof(*hdr); len -= sizeof(*hdr);
p += sizeof(*hdr); p += sizeof(*hdr);
while (len > 0) { while (len > 0) {
struct sadb_ext *ehdr = (struct sadb_ext *) p; const struct sadb_ext *ehdr = (const struct sadb_ext *) p;
uint16_t ext_type; uint16_t ext_type;
int ext_len; int ext_len;
...@@ -514,7 +515,7 @@ static int parse_exthdrs(struct sk_buff *skb, struct sadb_msg *hdr, void **ext_h ...@@ -514,7 +515,7 @@ static int parse_exthdrs(struct sk_buff *skb, struct sadb_msg *hdr, void **ext_h
if (verify_sec_ctx_len(p)) if (verify_sec_ctx_len(p))
return -EINVAL; return -EINVAL;
} }
ext_hdrs[ext_type-1] = p; ext_hdrs[ext_type-1] = (void *) p;
} }
p += ext_len; p += ext_len;
len -= ext_len; len -= ext_len;
...@@ -606,21 +607,21 @@ int pfkey_sockaddr_extract(const struct sockaddr *sa, xfrm_address_t *xaddr) ...@@ -606,21 +607,21 @@ int pfkey_sockaddr_extract(const struct sockaddr *sa, xfrm_address_t *xaddr)
} }
static static
int pfkey_sadb_addr2xfrm_addr(struct sadb_address *addr, xfrm_address_t *xaddr) int pfkey_sadb_addr2xfrm_addr(const struct sadb_address *addr, xfrm_address_t *xaddr)
{ {
return pfkey_sockaddr_extract((struct sockaddr *)(addr + 1), return pfkey_sockaddr_extract((struct sockaddr *)(addr + 1),
xaddr); xaddr);
} }
static struct xfrm_state *pfkey_xfrm_state_lookup(struct net *net, struct sadb_msg *hdr, void **ext_hdrs) static struct xfrm_state *pfkey_xfrm_state_lookup(struct net *net, const struct sadb_msg *hdr, void * const *ext_hdrs)
{ {
struct sadb_sa *sa; const struct sadb_sa *sa;
struct sadb_address *addr; const struct sadb_address *addr;
uint16_t proto; uint16_t proto;
unsigned short family; unsigned short family;
xfrm_address_t *xaddr; xfrm_address_t *xaddr;
sa = (struct sadb_sa *) ext_hdrs[SADB_EXT_SA-1]; sa = (const struct sadb_sa *) ext_hdrs[SADB_EXT_SA-1];
if (sa == NULL) if (sa == NULL)
return NULL; return NULL;
...@@ -629,18 +630,18 @@ static struct xfrm_state *pfkey_xfrm_state_lookup(struct net *net, struct sadb_ ...@@ -629,18 +630,18 @@ static struct xfrm_state *pfkey_xfrm_state_lookup(struct net *net, struct sadb_
return NULL; return NULL;
/* sadb_address_len should be checked by caller */ /* sadb_address_len should be checked by caller */
addr = (struct sadb_address *) ext_hdrs[SADB_EXT_ADDRESS_DST-1]; addr = (const struct sadb_address *) ext_hdrs[SADB_EXT_ADDRESS_DST-1];
if (addr == NULL) if (addr == NULL)
return NULL; return NULL;
family = ((struct sockaddr *)(addr + 1))->sa_family; family = ((const struct sockaddr *)(addr + 1))->sa_family;
switch (family) { switch (family) {
case AF_INET: case AF_INET:
xaddr = (xfrm_address_t *)&((struct sockaddr_in *)(addr + 1))->sin_addr; xaddr = (xfrm_address_t *)&((const struct sockaddr_in *)(addr + 1))->sin_addr;
break; break;
#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
case AF_INET6: case AF_INET6:
xaddr = (xfrm_address_t *)&((struct sockaddr_in6 *)(addr + 1))->sin6_addr; xaddr = (xfrm_address_t *)&((const struct sockaddr_in6 *)(addr + 1))->sin6_addr;
break; break;
#endif #endif
default: default:
...@@ -720,7 +721,7 @@ static unsigned int pfkey_sockaddr_fill(const xfrm_address_t *xaddr, __be16 port ...@@ -720,7 +721,7 @@ static unsigned int pfkey_sockaddr_fill(const xfrm_address_t *xaddr, __be16 port
return 0; return 0;
} }
static struct sk_buff *__pfkey_xfrm_state2msg(struct xfrm_state *x, static struct sk_buff *__pfkey_xfrm_state2msg(const struct xfrm_state *x,
int add_keys, int hsc) int add_keys, int hsc)
{ {
struct sk_buff *skb; struct sk_buff *skb;
...@@ -1010,7 +1011,7 @@ static struct sk_buff *__pfkey_xfrm_state2msg(struct xfrm_state *x, ...@@ -1010,7 +1011,7 @@ static struct sk_buff *__pfkey_xfrm_state2msg(struct xfrm_state *x,
} }
static inline struct sk_buff *pfkey_xfrm_state2msg(struct xfrm_state *x) static inline struct sk_buff *pfkey_xfrm_state2msg(const struct xfrm_state *x)
{ {
struct sk_buff *skb; struct sk_buff *skb;
...@@ -1019,26 +1020,26 @@ static inline struct sk_buff *pfkey_xfrm_state2msg(struct xfrm_state *x) ...@@ -1019,26 +1020,26 @@ static inline struct sk_buff *pfkey_xfrm_state2msg(struct xfrm_state *x)
return skb; return skb;
} }
static inline struct sk_buff *pfkey_xfrm_state2msg_expire(struct xfrm_state *x, static inline struct sk_buff *pfkey_xfrm_state2msg_expire(const struct xfrm_state *x,
int hsc) int hsc)
{ {
return __pfkey_xfrm_state2msg(x, 0, hsc); return __pfkey_xfrm_state2msg(x, 0, hsc);
} }
static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net, static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net,
struct sadb_msg *hdr, const struct sadb_msg *hdr,
void **ext_hdrs) void * const *ext_hdrs)
{ {
struct xfrm_state *x; struct xfrm_state *x;
struct sadb_lifetime *lifetime; const struct sadb_lifetime *lifetime;
struct sadb_sa *sa; const struct sadb_sa *sa;
struct sadb_key *key; const struct sadb_key *key;
struct sadb_x_sec_ctx *sec_ctx; const struct sadb_x_sec_ctx *sec_ctx;
uint16_t proto; uint16_t proto;
int err; int err;
sa = (struct sadb_sa *) ext_hdrs[SADB_EXT_SA-1]; sa = (const struct sadb_sa *) ext_hdrs[SADB_EXT_SA-1];
if (!sa || if (!sa ||
!present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC-1], !present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC-1],
ext_hdrs[SADB_EXT_ADDRESS_DST-1])) ext_hdrs[SADB_EXT_ADDRESS_DST-1]))
...@@ -1077,7 +1078,7 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net, ...@@ -1077,7 +1078,7 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net,
sa->sadb_sa_encrypt > SADB_X_CALG_MAX) || sa->sadb_sa_encrypt > SADB_X_CALG_MAX) ||
sa->sadb_sa_encrypt > SADB_EALG_MAX) sa->sadb_sa_encrypt > SADB_EALG_MAX)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
key = (struct sadb_key*) ext_hdrs[SADB_EXT_KEY_AUTH-1]; key = (const struct sadb_key*) ext_hdrs[SADB_EXT_KEY_AUTH-1];
if (key != NULL && if (key != NULL &&
sa->sadb_sa_auth != SADB_X_AALG_NULL && sa->sadb_sa_auth != SADB_X_AALG_NULL &&
((key->sadb_key_bits+7) / 8 == 0 || ((key->sadb_key_bits+7) / 8 == 0 ||
...@@ -1104,14 +1105,14 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net, ...@@ -1104,14 +1105,14 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net,
if (sa->sadb_sa_flags & SADB_SAFLAGS_NOPMTUDISC) if (sa->sadb_sa_flags & SADB_SAFLAGS_NOPMTUDISC)
x->props.flags |= XFRM_STATE_NOPMTUDISC; x->props.flags |= XFRM_STATE_NOPMTUDISC;
lifetime = (struct sadb_lifetime*) ext_hdrs[SADB_EXT_LIFETIME_HARD-1]; lifetime = (const struct sadb_lifetime*) ext_hdrs[SADB_EXT_LIFETIME_HARD-1];
if (lifetime != NULL) { if (lifetime != NULL) {
x->lft.hard_packet_limit = _KEY2X(lifetime->sadb_lifetime_allocations); x->lft.hard_packet_limit = _KEY2X(lifetime->sadb_lifetime_allocations);
x->lft.hard_byte_limit = _KEY2X(lifetime->sadb_lifetime_bytes); x->lft.hard_byte_limit = _KEY2X(lifetime->sadb_lifetime_bytes);
x->lft.hard_add_expires_seconds = lifetime->sadb_lifetime_addtime; x->lft.hard_add_expires_seconds = lifetime->sadb_lifetime_addtime;
x->lft.hard_use_expires_seconds = lifetime->sadb_lifetime_usetime; x->lft.hard_use_expires_seconds = lifetime->sadb_lifetime_usetime;
} }
lifetime = (struct sadb_lifetime*) ext_hdrs[SADB_EXT_LIFETIME_SOFT-1]; lifetime = (const struct sadb_lifetime*) ext_hdrs[SADB_EXT_LIFETIME_SOFT-1];
if (lifetime != NULL) { if (lifetime != NULL) {
x->lft.soft_packet_limit = _KEY2X(lifetime->sadb_lifetime_allocations); x->lft.soft_packet_limit = _KEY2X(lifetime->sadb_lifetime_allocations);
x->lft.soft_byte_limit = _KEY2X(lifetime->sadb_lifetime_bytes); x->lft.soft_byte_limit = _KEY2X(lifetime->sadb_lifetime_bytes);
...@@ -1119,7 +1120,7 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net, ...@@ -1119,7 +1120,7 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net,
x->lft.soft_use_expires_seconds = lifetime->sadb_lifetime_usetime; x->lft.soft_use_expires_seconds = lifetime->sadb_lifetime_usetime;
} }
sec_ctx = (struct sadb_x_sec_ctx *) ext_hdrs[SADB_X_EXT_SEC_CTX-1]; sec_ctx = (const struct sadb_x_sec_ctx *) ext_hdrs[SADB_X_EXT_SEC_CTX-1];
if (sec_ctx != NULL) { if (sec_ctx != NULL) {
struct xfrm_user_sec_ctx *uctx = pfkey_sadb2xfrm_user_sec_ctx(sec_ctx); struct xfrm_user_sec_ctx *uctx = pfkey_sadb2xfrm_user_sec_ctx(sec_ctx);
...@@ -1133,7 +1134,7 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net, ...@@ -1133,7 +1134,7 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net,
goto out; goto out;
} }
key = (struct sadb_key*) ext_hdrs[SADB_EXT_KEY_AUTH-1]; key = (const struct sadb_key*) ext_hdrs[SADB_EXT_KEY_AUTH-1];
if (sa->sadb_sa_auth) { if (sa->sadb_sa_auth) {
int keysize = 0; int keysize = 0;
struct xfrm_algo_desc *a = xfrm_aalg_get_byid(sa->sadb_sa_auth); struct xfrm_algo_desc *a = xfrm_aalg_get_byid(sa->sadb_sa_auth);
...@@ -1202,7 +1203,7 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net, ...@@ -1202,7 +1203,7 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net,
&x->id.daddr); &x->id.daddr);
if (ext_hdrs[SADB_X_EXT_SA2-1]) { if (ext_hdrs[SADB_X_EXT_SA2-1]) {
struct sadb_x_sa2 *sa2 = (void*)ext_hdrs[SADB_X_EXT_SA2-1]; const struct sadb_x_sa2 *sa2 = ext_hdrs[SADB_X_EXT_SA2-1];
int mode = pfkey_mode_to_xfrm(sa2->sadb_x_sa2_mode); int mode = pfkey_mode_to_xfrm(sa2->sadb_x_sa2_mode);
if (mode < 0) { if (mode < 0) {
err = -EINVAL; err = -EINVAL;
...@@ -1213,7 +1214,7 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net, ...@@ -1213,7 +1214,7 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net,
} }
if (ext_hdrs[SADB_EXT_ADDRESS_PROXY-1]) { if (ext_hdrs[SADB_EXT_ADDRESS_PROXY-1]) {
struct sadb_address *addr = ext_hdrs[SADB_EXT_ADDRESS_PROXY-1]; const struct sadb_address *addr = ext_hdrs[SADB_EXT_ADDRESS_PROXY-1];
/* Nobody uses this, but we try. */ /* Nobody uses this, but we try. */
x->sel.family = pfkey_sadb_addr2xfrm_addr(addr, &x->sel.saddr); x->sel.family = pfkey_sadb_addr2xfrm_addr(addr, &x->sel.saddr);
...@@ -1224,7 +1225,7 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net, ...@@ -1224,7 +1225,7 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net,
x->sel.family = x->props.family; x->sel.family = x->props.family;
if (ext_hdrs[SADB_X_EXT_NAT_T_TYPE-1]) { if (ext_hdrs[SADB_X_EXT_NAT_T_TYPE-1]) {
struct sadb_x_nat_t_type* n_type; const struct sadb_x_nat_t_type* n_type;
struct xfrm_encap_tmpl *natt; struct xfrm_encap_tmpl *natt;
x->encap = kmalloc(sizeof(*x->encap), GFP_KERNEL); x->encap = kmalloc(sizeof(*x->encap), GFP_KERNEL);
...@@ -1236,12 +1237,12 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net, ...@@ -1236,12 +1237,12 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net,
natt->encap_type = n_type->sadb_x_nat_t_type_type; natt->encap_type = n_type->sadb_x_nat_t_type_type;
if (ext_hdrs[SADB_X_EXT_NAT_T_SPORT-1]) { if (ext_hdrs[SADB_X_EXT_NAT_T_SPORT-1]) {
struct sadb_x_nat_t_port* n_port = const struct sadb_x_nat_t_port *n_port =
ext_hdrs[SADB_X_EXT_NAT_T_SPORT-1]; ext_hdrs[SADB_X_EXT_NAT_T_SPORT-1];
natt->encap_sport = n_port->sadb_x_nat_t_port_port; natt->encap_sport = n_port->sadb_x_nat_t_port_port;
} }
if (ext_hdrs[SADB_X_EXT_NAT_T_DPORT-1]) { if (ext_hdrs[SADB_X_EXT_NAT_T_DPORT-1]) {
struct sadb_x_nat_t_port* n_port = const struct sadb_x_nat_t_port *n_port =
ext_hdrs[SADB_X_EXT_NAT_T_DPORT-1]; ext_hdrs[SADB_X_EXT_NAT_T_DPORT-1];
natt->encap_dport = n_port->sadb_x_nat_t_port_port; natt->encap_dport = n_port->sadb_x_nat_t_port_port;
} }
...@@ -1261,12 +1262,12 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net, ...@@ -1261,12 +1262,12 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net,
return ERR_PTR(err); return ERR_PTR(err);
} }
static int pfkey_reserved(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs) static int pfkey_reserved(struct sock *sk, struct sk_buff *skb, const struct sadb_msg *hdr, void * const *ext_hdrs)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
static int pfkey_getspi(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs) static int pfkey_getspi(struct sock *sk, struct sk_buff *skb, const struct sadb_msg *hdr, void * const *ext_hdrs)
{ {
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
struct sk_buff *resp_skb; struct sk_buff *resp_skb;
...@@ -1365,7 +1366,7 @@ static int pfkey_getspi(struct sock *sk, struct sk_buff *skb, struct sadb_msg *h ...@@ -1365,7 +1366,7 @@ static int pfkey_getspi(struct sock *sk, struct sk_buff *skb, struct sadb_msg *h
return 0; return 0;
} }
static int pfkey_acquire(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs) static int pfkey_acquire(struct sock *sk, struct sk_buff *skb, const struct sadb_msg *hdr, void * const *ext_hdrs)
{ {
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
struct xfrm_state *x; struct xfrm_state *x;
...@@ -1453,7 +1454,7 @@ static int key_notify_sa(struct xfrm_state *x, const struct km_event *c) ...@@ -1453,7 +1454,7 @@ static int key_notify_sa(struct xfrm_state *x, const struct km_event *c)
return 0; return 0;
} }
static int pfkey_add(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs) static int pfkey_add(struct sock *sk, struct sk_buff *skb, const struct sadb_msg *hdr, void * const *ext_hdrs)
{ {
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
struct xfrm_state *x; struct xfrm_state *x;
...@@ -1492,7 +1493,7 @@ static int pfkey_add(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, ...@@ -1492,7 +1493,7 @@ static int pfkey_add(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr,
return err; return err;
} }
static int pfkey_delete(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs) static int pfkey_delete(struct sock *sk, struct sk_buff *skb, const struct sadb_msg *hdr, void * const *ext_hdrs)
{ {
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
struct xfrm_state *x; struct xfrm_state *x;
...@@ -1534,7 +1535,7 @@ static int pfkey_delete(struct sock *sk, struct sk_buff *skb, struct sadb_msg *h ...@@ -1534,7 +1535,7 @@ static int pfkey_delete(struct sock *sk, struct sk_buff *skb, struct sadb_msg *h
return err; return err;
} }
static int pfkey_get(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs) static int pfkey_get(struct sock *sk, struct sk_buff *skb, const struct sadb_msg *hdr, void * const *ext_hdrs)
{ {
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
__u8 proto; __u8 proto;
...@@ -1570,7 +1571,7 @@ static int pfkey_get(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, ...@@ -1570,7 +1571,7 @@ static int pfkey_get(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr,
return 0; return 0;
} }
static struct sk_buff *compose_sadb_supported(struct sadb_msg *orig, static struct sk_buff *compose_sadb_supported(const struct sadb_msg *orig,
gfp_t allocation) gfp_t allocation)
{ {
struct sk_buff *skb; struct sk_buff *skb;
...@@ -1642,7 +1643,7 @@ static struct sk_buff *compose_sadb_supported(struct sadb_msg *orig, ...@@ -1642,7 +1643,7 @@ static struct sk_buff *compose_sadb_supported(struct sadb_msg *orig,
return skb; return skb;
} }
static int pfkey_register(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs) static int pfkey_register(struct sock *sk, struct sk_buff *skb, const struct sadb_msg *hdr, void * const *ext_hdrs)
{ {
struct pfkey_sock *pfk = pfkey_sk(sk); struct pfkey_sock *pfk = pfkey_sk(sk);
struct sk_buff *supp_skb; struct sk_buff *supp_skb;
...@@ -1671,7 +1672,7 @@ static int pfkey_register(struct sock *sk, struct sk_buff *skb, struct sadb_msg ...@@ -1671,7 +1672,7 @@ static int pfkey_register(struct sock *sk, struct sk_buff *skb, struct sadb_msg
return 0; return 0;
} }
static int unicast_flush_resp(struct sock *sk, struct sadb_msg *ihdr) static int unicast_flush_resp(struct sock *sk, const struct sadb_msg *ihdr)
{ {
struct sk_buff *skb; struct sk_buff *skb;
struct sadb_msg *hdr; struct sadb_msg *hdr;
...@@ -1710,7 +1711,7 @@ static int key_notify_sa_flush(const struct km_event *c) ...@@ -1710,7 +1711,7 @@ static int key_notify_sa_flush(const struct km_event *c)
return 0; return 0;
} }
static int pfkey_flush(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs) static int pfkey_flush(struct sock *sk, struct sk_buff *skb, const struct sadb_msg *hdr, void * const *ext_hdrs)
{ {
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
unsigned proto; unsigned proto;
...@@ -1784,7 +1785,7 @@ static void pfkey_dump_sa_done(struct pfkey_sock *pfk) ...@@ -1784,7 +1785,7 @@ static void pfkey_dump_sa_done(struct pfkey_sock *pfk)
xfrm_state_walk_done(&pfk->dump.u.state); xfrm_state_walk_done(&pfk->dump.u.state);
} }
static int pfkey_dump(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs) static int pfkey_dump(struct sock *sk, struct sk_buff *skb, const struct sadb_msg *hdr, void * const *ext_hdrs)
{ {
u8 proto; u8 proto;
struct pfkey_sock *pfk = pfkey_sk(sk); struct pfkey_sock *pfk = pfkey_sk(sk);
...@@ -1805,19 +1806,29 @@ static int pfkey_dump(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr ...@@ -1805,19 +1806,29 @@ static int pfkey_dump(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr
return pfkey_do_dump(pfk); return pfkey_do_dump(pfk);
} }
static int pfkey_promisc(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs) static int pfkey_promisc(struct sock *sk, struct sk_buff *skb, const struct sadb_msg *hdr, void * const *ext_hdrs)
{ {
struct pfkey_sock *pfk = pfkey_sk(sk); struct pfkey_sock *pfk = pfkey_sk(sk);
int satype = hdr->sadb_msg_satype; int satype = hdr->sadb_msg_satype;
bool reset_errno = false;
if (hdr->sadb_msg_len == (sizeof(*hdr) / sizeof(uint64_t))) { if (hdr->sadb_msg_len == (sizeof(*hdr) / sizeof(uint64_t))) {
/* XXX we mangle packet... */ reset_errno = true;
hdr->sadb_msg_errno = 0;
if (satype != 0 && satype != 1) if (satype != 0 && satype != 1)
return -EINVAL; return -EINVAL;
pfk->promisc = satype; pfk->promisc = satype;
} }
pfkey_broadcast(skb_clone(skb, GFP_KERNEL), GFP_KERNEL, BROADCAST_ALL, NULL, sock_net(sk)); if (reset_errno && skb_cloned(skb))
skb = skb_copy(skb, GFP_KERNEL);
else
skb = skb_clone(skb, GFP_KERNEL);
if (reset_errno && skb) {
struct sadb_msg *new_hdr = (struct sadb_msg *) skb->data;
new_hdr->sadb_msg_errno = 0;
}
pfkey_broadcast(skb, GFP_KERNEL, BROADCAST_ALL, NULL, sock_net(sk));
return 0; return 0;
} }
...@@ -1921,7 +1932,7 @@ parse_ipsecrequests(struct xfrm_policy *xp, struct sadb_x_policy *pol) ...@@ -1921,7 +1932,7 @@ parse_ipsecrequests(struct xfrm_policy *xp, struct sadb_x_policy *pol)
return 0; return 0;
} }
static inline int pfkey_xfrm_policy2sec_ctx_size(struct xfrm_policy *xp) static inline int pfkey_xfrm_policy2sec_ctx_size(const struct xfrm_policy *xp)
{ {
struct xfrm_sec_ctx *xfrm_ctx = xp->security; struct xfrm_sec_ctx *xfrm_ctx = xp->security;
...@@ -1933,9 +1944,9 @@ static inline int pfkey_xfrm_policy2sec_ctx_size(struct xfrm_policy *xp) ...@@ -1933,9 +1944,9 @@ static inline int pfkey_xfrm_policy2sec_ctx_size(struct xfrm_policy *xp)
return 0; return 0;
} }
static int pfkey_xfrm_policy2msg_size(struct xfrm_policy *xp) static int pfkey_xfrm_policy2msg_size(const struct xfrm_policy *xp)
{ {
struct xfrm_tmpl *t; const struct xfrm_tmpl *t;
int sockaddr_size = pfkey_sockaddr_size(xp->family); int sockaddr_size = pfkey_sockaddr_size(xp->family);
int socklen = 0; int socklen = 0;
int i; int i;
...@@ -1955,7 +1966,7 @@ static int pfkey_xfrm_policy2msg_size(struct xfrm_policy *xp) ...@@ -1955,7 +1966,7 @@ static int pfkey_xfrm_policy2msg_size(struct xfrm_policy *xp)
pfkey_xfrm_policy2sec_ctx_size(xp); pfkey_xfrm_policy2sec_ctx_size(xp);
} }
static struct sk_buff * pfkey_xfrm_policy2msg_prep(struct xfrm_policy *xp) static struct sk_buff * pfkey_xfrm_policy2msg_prep(const struct xfrm_policy *xp)
{ {
struct sk_buff *skb; struct sk_buff *skb;
int size; int size;
...@@ -1969,7 +1980,7 @@ static struct sk_buff * pfkey_xfrm_policy2msg_prep(struct xfrm_policy *xp) ...@@ -1969,7 +1980,7 @@ static struct sk_buff * pfkey_xfrm_policy2msg_prep(struct xfrm_policy *xp)
return skb; return skb;
} }
static int pfkey_xfrm_policy2msg(struct sk_buff *skb, struct xfrm_policy *xp, int dir) static int pfkey_xfrm_policy2msg(struct sk_buff *skb, const struct xfrm_policy *xp, int dir)
{ {
struct sadb_msg *hdr; struct sadb_msg *hdr;
struct sadb_address *addr; struct sadb_address *addr;
...@@ -2065,8 +2076,8 @@ static int pfkey_xfrm_policy2msg(struct sk_buff *skb, struct xfrm_policy *xp, in ...@@ -2065,8 +2076,8 @@ static int pfkey_xfrm_policy2msg(struct sk_buff *skb, struct xfrm_policy *xp, in
pol->sadb_x_policy_priority = xp->priority; pol->sadb_x_policy_priority = xp->priority;
for (i=0; i<xp->xfrm_nr; i++) { for (i=0; i<xp->xfrm_nr; i++) {
const struct xfrm_tmpl *t = xp->xfrm_vec + i;
struct sadb_x_ipsecrequest *rq; struct sadb_x_ipsecrequest *rq;
struct xfrm_tmpl *t = xp->xfrm_vec + i;
int req_size; int req_size;
int mode; int mode;
...@@ -2152,7 +2163,7 @@ static int key_notify_policy(struct xfrm_policy *xp, int dir, const struct km_ev ...@@ -2152,7 +2163,7 @@ static int key_notify_policy(struct xfrm_policy *xp, int dir, const struct km_ev
} }
static int pfkey_spdadd(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs) static int pfkey_spdadd(struct sock *sk, struct sk_buff *skb, const struct sadb_msg *hdr, void * const *ext_hdrs)
{ {
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
int err = 0; int err = 0;
...@@ -2273,7 +2284,7 @@ static int pfkey_spdadd(struct sock *sk, struct sk_buff *skb, struct sadb_msg *h ...@@ -2273,7 +2284,7 @@ static int pfkey_spdadd(struct sock *sk, struct sk_buff *skb, struct sadb_msg *h
return err; return err;
} }
static int pfkey_spddelete(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs) static int pfkey_spddelete(struct sock *sk, struct sk_buff *skb, const struct sadb_msg *hdr, void * const *ext_hdrs)
{ {
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
int err; int err;
...@@ -2350,7 +2361,7 @@ static int pfkey_spddelete(struct sock *sk, struct sk_buff *skb, struct sadb_msg ...@@ -2350,7 +2361,7 @@ static int pfkey_spddelete(struct sock *sk, struct sk_buff *skb, struct sadb_msg
return err; return err;
} }
static int key_pol_get_resp(struct sock *sk, struct xfrm_policy *xp, struct sadb_msg *hdr, int dir) static int key_pol_get_resp(struct sock *sk, struct xfrm_policy *xp, const struct sadb_msg *hdr, int dir)
{ {
int err; int err;
struct sk_buff *out_skb; struct sk_buff *out_skb;
...@@ -2458,7 +2469,7 @@ static int ipsecrequests_to_migrate(struct sadb_x_ipsecrequest *rq1, int len, ...@@ -2458,7 +2469,7 @@ static int ipsecrequests_to_migrate(struct sadb_x_ipsecrequest *rq1, int len,
} }
static int pfkey_migrate(struct sock *sk, struct sk_buff *skb, static int pfkey_migrate(struct sock *sk, struct sk_buff *skb,
struct sadb_msg *hdr, void **ext_hdrs) const struct sadb_msg *hdr, void * const *ext_hdrs)
{ {
int i, len, ret, err = -EINVAL; int i, len, ret, err = -EINVAL;
u8 dir; u8 dir;
...@@ -2556,7 +2567,7 @@ static int pfkey_migrate(struct sock *sk, struct sk_buff *skb, ...@@ -2556,7 +2567,7 @@ static int pfkey_migrate(struct sock *sk, struct sk_buff *skb,
#endif #endif
static int pfkey_spdget(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs) static int pfkey_spdget(struct sock *sk, struct sk_buff *skb, const struct sadb_msg *hdr, void * const *ext_hdrs)
{ {
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
unsigned int dir; unsigned int dir;
...@@ -2644,7 +2655,7 @@ static void pfkey_dump_sp_done(struct pfkey_sock *pfk) ...@@ -2644,7 +2655,7 @@ static void pfkey_dump_sp_done(struct pfkey_sock *pfk)
xfrm_policy_walk_done(&pfk->dump.u.policy); xfrm_policy_walk_done(&pfk->dump.u.policy);
} }
static int pfkey_spddump(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs) static int pfkey_spddump(struct sock *sk, struct sk_buff *skb, const struct sadb_msg *hdr, void * const *ext_hdrs)
{ {
struct pfkey_sock *pfk = pfkey_sk(sk); struct pfkey_sock *pfk = pfkey_sk(sk);
...@@ -2680,7 +2691,7 @@ static int key_notify_policy_flush(const struct km_event *c) ...@@ -2680,7 +2691,7 @@ static int key_notify_policy_flush(const struct km_event *c)
} }
static int pfkey_spdflush(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs) static int pfkey_spdflush(struct sock *sk, struct sk_buff *skb, const struct sadb_msg *hdr, void * const *ext_hdrs)
{ {
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
struct km_event c; struct km_event c;
...@@ -2709,7 +2720,7 @@ static int pfkey_spdflush(struct sock *sk, struct sk_buff *skb, struct sadb_msg ...@@ -2709,7 +2720,7 @@ static int pfkey_spdflush(struct sock *sk, struct sk_buff *skb, struct sadb_msg
} }
typedef int (*pfkey_handler)(struct sock *sk, struct sk_buff *skb, typedef int (*pfkey_handler)(struct sock *sk, struct sk_buff *skb,
struct sadb_msg *hdr, void **ext_hdrs); const struct sadb_msg *hdr, void * const *ext_hdrs);
static pfkey_handler pfkey_funcs[SADB_MAX + 1] = { static pfkey_handler pfkey_funcs[SADB_MAX + 1] = {
[SADB_RESERVED] = pfkey_reserved, [SADB_RESERVED] = pfkey_reserved,
[SADB_GETSPI] = pfkey_getspi, [SADB_GETSPI] = pfkey_getspi,
...@@ -2736,7 +2747,7 @@ static pfkey_handler pfkey_funcs[SADB_MAX + 1] = { ...@@ -2736,7 +2747,7 @@ static pfkey_handler pfkey_funcs[SADB_MAX + 1] = {
[SADB_X_MIGRATE] = pfkey_migrate, [SADB_X_MIGRATE] = pfkey_migrate,
}; };
static int pfkey_process(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr) static int pfkey_process(struct sock *sk, struct sk_buff *skb, const struct sadb_msg *hdr)
{ {
void *ext_hdrs[SADB_EXT_MAX]; void *ext_hdrs[SADB_EXT_MAX];
int err; int err;
...@@ -2781,7 +2792,8 @@ static struct sadb_msg *pfkey_get_base_msg(struct sk_buff *skb, int *errp) ...@@ -2781,7 +2792,8 @@ static struct sadb_msg *pfkey_get_base_msg(struct sk_buff *skb, int *errp)
return hdr; return hdr;
} }
static inline int aalg_tmpl_set(struct xfrm_tmpl *t, struct xfrm_algo_desc *d) static inline int aalg_tmpl_set(const struct xfrm_tmpl *t,
const struct xfrm_algo_desc *d)
{ {
unsigned int id = d->desc.sadb_alg_id; unsigned int id = d->desc.sadb_alg_id;
...@@ -2791,7 +2803,8 @@ static inline int aalg_tmpl_set(struct xfrm_tmpl *t, struct xfrm_algo_desc *d) ...@@ -2791,7 +2803,8 @@ static inline int aalg_tmpl_set(struct xfrm_tmpl *t, struct xfrm_algo_desc *d)
return (t->aalgos >> id) & 1; return (t->aalgos >> id) & 1;
} }
static inline int ealg_tmpl_set(struct xfrm_tmpl *t, struct xfrm_algo_desc *d) static inline int ealg_tmpl_set(const struct xfrm_tmpl *t,
const struct xfrm_algo_desc *d)
{ {
unsigned int id = d->desc.sadb_alg_id; unsigned int id = d->desc.sadb_alg_id;
...@@ -2801,12 +2814,12 @@ static inline int ealg_tmpl_set(struct xfrm_tmpl *t, struct xfrm_algo_desc *d) ...@@ -2801,12 +2814,12 @@ static inline int ealg_tmpl_set(struct xfrm_tmpl *t, struct xfrm_algo_desc *d)
return (t->ealgos >> id) & 1; return (t->ealgos >> id) & 1;
} }
static int count_ah_combs(struct xfrm_tmpl *t) static int count_ah_combs(const struct xfrm_tmpl *t)
{ {
int i, sz = 0; int i, sz = 0;
for (i = 0; ; i++) { for (i = 0; ; i++) {
struct xfrm_algo_desc *aalg = xfrm_aalg_get_byidx(i); const struct xfrm_algo_desc *aalg = xfrm_aalg_get_byidx(i);
if (!aalg) if (!aalg)
break; break;
if (aalg_tmpl_set(t, aalg) && aalg->available) if (aalg_tmpl_set(t, aalg) && aalg->available)
...@@ -2815,12 +2828,12 @@ static int count_ah_combs(struct xfrm_tmpl *t) ...@@ -2815,12 +2828,12 @@ static int count_ah_combs(struct xfrm_tmpl *t)
return sz + sizeof(struct sadb_prop); return sz + sizeof(struct sadb_prop);
} }
static int count_esp_combs(struct xfrm_tmpl *t) static int count_esp_combs(const struct xfrm_tmpl *t)
{ {
int i, k, sz = 0; int i, k, sz = 0;
for (i = 0; ; i++) { for (i = 0; ; i++) {
struct xfrm_algo_desc *ealg = xfrm_ealg_get_byidx(i); const struct xfrm_algo_desc *ealg = xfrm_ealg_get_byidx(i);
if (!ealg) if (!ealg)
break; break;
...@@ -2828,7 +2841,7 @@ static int count_esp_combs(struct xfrm_tmpl *t) ...@@ -2828,7 +2841,7 @@ static int count_esp_combs(struct xfrm_tmpl *t)
continue; continue;
for (k = 1; ; k++) { for (k = 1; ; k++) {
struct xfrm_algo_desc *aalg = xfrm_aalg_get_byidx(k); const struct xfrm_algo_desc *aalg = xfrm_aalg_get_byidx(k);
if (!aalg) if (!aalg)
break; break;
...@@ -2839,7 +2852,7 @@ static int count_esp_combs(struct xfrm_tmpl *t) ...@@ -2839,7 +2852,7 @@ static int count_esp_combs(struct xfrm_tmpl *t)
return sz + sizeof(struct sadb_prop); return sz + sizeof(struct sadb_prop);
} }
static void dump_ah_combs(struct sk_buff *skb, struct xfrm_tmpl *t) static void dump_ah_combs(struct sk_buff *skb, const struct xfrm_tmpl *t)
{ {
struct sadb_prop *p; struct sadb_prop *p;
int i; int i;
...@@ -2851,7 +2864,7 @@ static void dump_ah_combs(struct sk_buff *skb, struct xfrm_tmpl *t) ...@@ -2851,7 +2864,7 @@ static void dump_ah_combs(struct sk_buff *skb, struct xfrm_tmpl *t)
memset(p->sadb_prop_reserved, 0, sizeof(p->sadb_prop_reserved)); memset(p->sadb_prop_reserved, 0, sizeof(p->sadb_prop_reserved));
for (i = 0; ; i++) { for (i = 0; ; i++) {
struct xfrm_algo_desc *aalg = xfrm_aalg_get_byidx(i); const struct xfrm_algo_desc *aalg = xfrm_aalg_get_byidx(i);
if (!aalg) if (!aalg)
break; break;
...@@ -2871,7 +2884,7 @@ static void dump_ah_combs(struct sk_buff *skb, struct xfrm_tmpl *t) ...@@ -2871,7 +2884,7 @@ static void dump_ah_combs(struct sk_buff *skb, struct xfrm_tmpl *t)
} }
} }
static void dump_esp_combs(struct sk_buff *skb, struct xfrm_tmpl *t) static void dump_esp_combs(struct sk_buff *skb, const struct xfrm_tmpl *t)
{ {
struct sadb_prop *p; struct sadb_prop *p;
int i, k; int i, k;
...@@ -2883,7 +2896,7 @@ static void dump_esp_combs(struct sk_buff *skb, struct xfrm_tmpl *t) ...@@ -2883,7 +2896,7 @@ static void dump_esp_combs(struct sk_buff *skb, struct xfrm_tmpl *t)
memset(p->sadb_prop_reserved, 0, sizeof(p->sadb_prop_reserved)); memset(p->sadb_prop_reserved, 0, sizeof(p->sadb_prop_reserved));
for (i=0; ; i++) { for (i=0; ; i++) {
struct xfrm_algo_desc *ealg = xfrm_ealg_get_byidx(i); const struct xfrm_algo_desc *ealg = xfrm_ealg_get_byidx(i);
if (!ealg) if (!ealg)
break; break;
...@@ -2892,7 +2905,7 @@ static void dump_esp_combs(struct sk_buff *skb, struct xfrm_tmpl *t) ...@@ -2892,7 +2905,7 @@ static void dump_esp_combs(struct sk_buff *skb, struct xfrm_tmpl *t)
for (k = 1; ; k++) { for (k = 1; ; k++) {
struct sadb_comb *c; struct sadb_comb *c;
struct xfrm_algo_desc *aalg = xfrm_aalg_get_byidx(k); const struct xfrm_algo_desc *aalg = xfrm_aalg_get_byidx(k);
if (!aalg) if (!aalg)
break; break;
if (!(aalg_tmpl_set(t, aalg) && aalg->available)) if (!(aalg_tmpl_set(t, aalg) && aalg->available))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment