Skip to content

Commit

Permalink
inet: constify ip headers and in6_addr
Browse files Browse the repository at this point in the history
Add const qualifiers to structs iphdr, ipv6hdr and in6_addr pointers
where possible, to make code intention more obvious.

Signed-off-by: Eric Dumazet <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Eric Dumazet authored and davem330 committed Apr 22, 2011
1 parent 5f8629c commit b71d1d4
Show file tree
Hide file tree
Showing 64 changed files with 316 additions and 310 deletions.
22 changes: 11 additions & 11 deletions include/net/addrconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ extern int addrconf_set_dstaddr(struct net *net,
void __user *arg);

extern int ipv6_chk_addr(struct net *net,
struct in6_addr *addr,
const struct in6_addr *addr,
struct net_device *dev,
int strict);

#if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
extern int ipv6_chk_home_addr(struct net *net,
struct in6_addr *addr);
const struct in6_addr *addr);
#endif

extern int ipv6_chk_prefix(struct in6_addr *addr,
extern int ipv6_chk_prefix(const struct in6_addr *addr,
struct net_device *dev);

extern struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net,
Expand All @@ -89,9 +89,9 @@ extern int ipv6_get_lladdr(struct net_device *dev,
extern int ipv6_rcv_saddr_equal(const struct sock *sk,
const struct sock *sk2);
extern void addrconf_join_solict(struct net_device *dev,
struct in6_addr *addr);
const struct in6_addr *addr);
extern void addrconf_leave_solict(struct inet6_dev *idev,
struct in6_addr *addr);
const struct in6_addr *addr);

static inline unsigned long addrconf_timeout_fixup(u32 timeout,
unsigned unit)
Expand Down Expand Up @@ -158,15 +158,15 @@ extern void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len);
/*
* anycast prototypes (anycast.c)
*/
extern int ipv6_sock_ac_join(struct sock *sk,int ifindex,struct in6_addr *addr);
extern int ipv6_sock_ac_drop(struct sock *sk,int ifindex,struct in6_addr *addr);
extern int ipv6_sock_ac_join(struct sock *sk,int ifindex, const struct in6_addr *addr);
extern int ipv6_sock_ac_drop(struct sock *sk,int ifindex, const struct in6_addr *addr);
extern void ipv6_sock_ac_close(struct sock *sk);
extern int inet6_ac_check(struct sock *sk, struct in6_addr *addr, int ifindex);
extern int inet6_ac_check(struct sock *sk, const struct in6_addr *addr, int ifindex);

extern int ipv6_dev_ac_inc(struct net_device *dev, struct in6_addr *addr);
extern int __ipv6_dev_ac_dec(struct inet6_dev *idev, struct in6_addr *addr);
extern int ipv6_dev_ac_inc(struct net_device *dev, const struct in6_addr *addr);
extern int __ipv6_dev_ac_dec(struct inet6_dev *idev, const struct in6_addr *addr);
extern int ipv6_chk_acast_addr(struct net *net, struct net_device *dev,
struct in6_addr *addr);
const struct in6_addr *addr);


/* Device notifier */
Expand Down
4 changes: 2 additions & 2 deletions include/net/if_inet6.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ struct inet6_dev {
struct rcu_head rcu;
};

static inline void ipv6_eth_mc_map(struct in6_addr *addr, char *buf)
static inline void ipv6_eth_mc_map(const struct in6_addr *addr, char *buf)
{
/*
* +-------+-------+-------+-------+-------+-------+
Expand All @@ -210,7 +210,7 @@ static inline void ipv6_eth_mc_map(struct in6_addr *addr, char *buf)
memcpy(buf + 2, &addr->s6_addr32[3], sizeof(__u32));
}

static inline void ipv6_tr_mc_map(struct in6_addr *addr, char *buf)
static inline void ipv6_tr_mc_map(const struct in6_addr *addr, char *buf)
{
/* All nodes FF01::1, FF02::1, FF02::1:FFxx:xxxx */

Expand Down
2 changes: 1 addition & 1 deletion include/net/inetpeer.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static inline struct inet_peer *inet_getpeer_v4(__be32 v4daddr, int create)
return inet_getpeer(&daddr, create);
}

static inline struct inet_peer *inet_getpeer_v6(struct in6_addr *v6daddr, int create)
static inline struct inet_peer *inet_getpeer_v6(const struct in6_addr *v6daddr, int create)
{
struct inetpeer_addr daddr;

Expand Down
8 changes: 4 additions & 4 deletions include/net/ip6_fib.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ extern struct dst_entry *fib6_rule_lookup(struct net *net,
pol_lookup_t lookup);

extern struct fib6_node *fib6_lookup(struct fib6_node *root,
struct in6_addr *daddr,
struct in6_addr *saddr);
const struct in6_addr *daddr,
const struct in6_addr *saddr);

struct fib6_node *fib6_locate(struct fib6_node *root,
struct in6_addr *daddr, int dst_len,
struct in6_addr *saddr, int src_len);
const struct in6_addr *daddr, int dst_len,
const struct in6_addr *saddr, int src_len);

extern void fib6_clean_all(struct net *net,
int (*func)(struct rt6_info *, void *arg),
Expand Down
18 changes: 9 additions & 9 deletions include/net/ip6_route.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ extern int ip6_del_rt(struct rt6_info *);

extern int ip6_route_get_saddr(struct net *net,
struct rt6_info *rt,
struct in6_addr *daddr,
const struct in6_addr *daddr,
unsigned int prefs,
struct in6_addr *saddr);

Expand All @@ -112,27 +112,27 @@ extern int ip6_dst_hoplimit(struct dst_entry *dst);
* support functions for ND
*
*/
extern struct rt6_info * rt6_get_dflt_router(struct in6_addr *addr,
extern struct rt6_info * rt6_get_dflt_router(const struct in6_addr *addr,
struct net_device *dev);
extern struct rt6_info * rt6_add_dflt_router(struct in6_addr *gwaddr,
extern struct rt6_info * rt6_add_dflt_router(const struct in6_addr *gwaddr,
struct net_device *dev,
unsigned int pref);

extern void rt6_purge_dflt_routers(struct net *net);

extern int rt6_route_rcv(struct net_device *dev,
u8 *opt, int len,
struct in6_addr *gwaddr);
const struct in6_addr *gwaddr);

extern void rt6_redirect(struct in6_addr *dest,
struct in6_addr *src,
struct in6_addr *saddr,
extern void rt6_redirect(const struct in6_addr *dest,
const struct in6_addr *src,
const struct in6_addr *saddr,
struct neighbour *neigh,
u8 *lladdr,
int on_link);

extern void rt6_pmtu_discovery(struct in6_addr *daddr,
struct in6_addr *saddr,
extern void rt6_pmtu_discovery(const struct in6_addr *daddr,
const struct in6_addr *saddr,
struct net_device *dev,
u32 pmtu);

Expand Down
4 changes: 2 additions & 2 deletions include/net/ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ enum ip6_defrag_users {
struct ip6_create_arg {
__be32 id;
u32 user;
struct in6_addr *src;
struct in6_addr *dst;
const struct in6_addr *src;
const struct in6_addr *dst;
};

void ip6_frag_init(struct inet_frag_queue *q, void *a);
Expand Down
3 changes: 2 additions & 1 deletion include/net/ndisc.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ extern void ndisc_send_redirect(struct sk_buff *skb,
struct neighbour *neigh,
const struct in6_addr *target);

extern int ndisc_mc_map(struct in6_addr *addr, char *buf, struct net_device *dev, int dir);
extern int ndisc_mc_map(const struct in6_addr *addr, char *buf,
struct net_device *dev, int dir);

extern struct sk_buff *ndisc_build_skb(struct net_device *dev,
const struct in6_addr *daddr,
Expand Down
3 changes: 2 additions & 1 deletion include/net/route.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ static inline int ip_route_input_noref(struct sk_buff *skb, __be32 dst, __be32 s
return ip_route_input_common(skb, dst, src, tos, devin, true);
}

extern unsigned short ip_rt_frag_needed(struct net *net, struct iphdr *iph, unsigned short new_mtu, struct net_device *dev);
extern unsigned short ip_rt_frag_needed(struct net *net, const struct iphdr *iph,
unsigned short new_mtu, struct net_device *dev);
extern void ip_rt_send_redirect(struct sk_buff *skb);

extern unsigned inet_addr_type(struct net *net, __be32 addr);
Expand Down
6 changes: 3 additions & 3 deletions include/net/xfrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,7 @@ extern int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr,
extern int xfrm6_tunnel_register(struct xfrm6_tunnel *handler, unsigned short family);
extern int xfrm6_tunnel_deregister(struct xfrm6_tunnel *handler, unsigned short family);
extern __be32 xfrm6_tunnel_alloc_spi(struct net *net, xfrm_address_t *saddr);
extern __be32 xfrm6_tunnel_spi_lookup(struct net *net, xfrm_address_t *saddr);
extern __be32 xfrm6_tunnel_spi_lookup(struct net *net, const xfrm_address_t *saddr);
extern int xfrm6_extract_output(struct xfrm_state *x, struct sk_buff *skb);
extern int xfrm6_prepare_output(struct xfrm_state *x, struct sk_buff *skb);
extern int xfrm6_output(struct sk_buff *skb);
Expand Down Expand Up @@ -1569,8 +1569,8 @@ static inline int xfrm_addr_cmp(const xfrm_address_t *a,
case AF_INET:
return (__force u32)a->a4 - (__force u32)b->a4;
case AF_INET6:
return ipv6_addr_cmp((struct in6_addr *)a,
(struct in6_addr *)b);
return ipv6_addr_cmp((const struct in6_addr *)a,
(const struct in6_addr *)b);
}
}

Expand Down
12 changes: 6 additions & 6 deletions net/bridge/br_multicast.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ static struct sk_buff *br_ip4_multicast_alloc_query(struct net_bridge *br,

#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
static struct sk_buff *br_ip6_multicast_alloc_query(struct net_bridge *br,
struct in6_addr *group)
const struct in6_addr *group)
{
struct sk_buff *skb;
struct ipv6hdr *ip6h;
Expand Down Expand Up @@ -1115,7 +1115,7 @@ static int br_ip4_multicast_query(struct net_bridge *br,
struct net_bridge_port *port,
struct sk_buff *skb)
{
struct iphdr *iph = ip_hdr(skb);
const struct iphdr *iph = ip_hdr(skb);
struct igmphdr *ih = igmp_hdr(skb);
struct net_bridge_mdb_entry *mp;
struct igmpv3_query *ih3;
Expand Down Expand Up @@ -1190,15 +1190,15 @@ static int br_ip6_multicast_query(struct net_bridge *br,
struct net_bridge_port *port,
struct sk_buff *skb)
{
struct ipv6hdr *ip6h = ipv6_hdr(skb);
const struct ipv6hdr *ip6h = ipv6_hdr(skb);
struct mld_msg *mld = (struct mld_msg *) icmp6_hdr(skb);
struct net_bridge_mdb_entry *mp;
struct mld2_query *mld2q;
struct net_bridge_port_group *p;
struct net_bridge_port_group __rcu **pp;
unsigned long max_delay;
unsigned long now = jiffies;
struct in6_addr *group = NULL;
const struct in6_addr *group = NULL;
int err = 0;

spin_lock(&br->multicast_lock);
Expand Down Expand Up @@ -1356,7 +1356,7 @@ static int br_multicast_ipv4_rcv(struct net_bridge *br,
struct sk_buff *skb)
{
struct sk_buff *skb2 = skb;
struct iphdr *iph;
const struct iphdr *iph;
struct igmphdr *ih;
unsigned len;
unsigned offset;
Expand Down Expand Up @@ -1452,7 +1452,7 @@ static int br_multicast_ipv6_rcv(struct net_bridge *br,
struct sk_buff *skb)
{
struct sk_buff *skb2;
struct ipv6hdr *ip6h;
const struct ipv6hdr *ip6h;
struct icmp6hdr *icmp6h;
u8 nexthdr;
unsigned len;
Expand Down
4 changes: 2 additions & 2 deletions net/bridge/br_netfilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ static inline void nf_bridge_update_protocol(struct sk_buff *skb)
static int br_parse_ip_options(struct sk_buff *skb)
{
struct ip_options *opt;
struct iphdr *iph;
const struct iphdr *iph;
struct net_device *dev = skb->dev;
u32 len;

Expand Down Expand Up @@ -554,7 +554,7 @@ static unsigned int br_nf_pre_routing_ipv6(unsigned int hook,
const struct net_device *out,
int (*okfn)(struct sk_buff *))
{
struct ipv6hdr *hdr;
const struct ipv6hdr *hdr;
u32 pkt_len;

if (skb->len < sizeof(struct ipv6hdr))
Expand Down
8 changes: 4 additions & 4 deletions net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -2502,8 +2502,8 @@ static inline void ____napi_schedule(struct softnet_data *sd,
__u32 __skb_get_rxhash(struct sk_buff *skb)
{
int nhoff, hash = 0, poff;
struct ipv6hdr *ip6;
struct iphdr *ip;
const struct ipv6hdr *ip6;
const struct iphdr *ip;
u8 ip_proto;
u32 addr1, addr2, ihl;
union {
Expand All @@ -2518,7 +2518,7 @@ __u32 __skb_get_rxhash(struct sk_buff *skb)
if (!pskb_may_pull(skb, sizeof(*ip) + nhoff))
goto done;

ip = (struct iphdr *) (skb->data + nhoff);
ip = (const struct iphdr *) (skb->data + nhoff);
if (ip->frag_off & htons(IP_MF | IP_OFFSET))
ip_proto = 0;
else
Expand All @@ -2531,7 +2531,7 @@ __u32 __skb_get_rxhash(struct sk_buff *skb)
if (!pskb_may_pull(skb, sizeof(*ip6) + nhoff))
goto done;

ip6 = (struct ipv6hdr *) (skb->data + nhoff);
ip6 = (const struct ipv6hdr *) (skb->data + nhoff);
ip_proto = ip6->nexthdr;
addr1 = (__force u32) ip6->saddr.s6_addr32[3];
addr2 = (__force u32) ip6->daddr.s6_addr32[3];
Expand Down
2 changes: 1 addition & 1 deletion net/core/netpoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ int __netpoll_rx(struct sk_buff *skb)
{
int proto, len, ulen;
int hits = 0;
struct iphdr *iph;
const struct iphdr *iph;
struct udphdr *uh;
struct netpoll_info *npinfo = skb->dev->npinfo;
struct netpoll *np, *tmp;
Expand Down
8 changes: 4 additions & 4 deletions net/dccp/ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ static void dccp_v6_hash(struct sock *sk)

/* add pseudo-header to DCCP checksum stored in skb->csum */
static inline __sum16 dccp_v6_csum_finish(struct sk_buff *skb,
struct in6_addr *saddr,
struct in6_addr *daddr)
const struct in6_addr *saddr,
const struct in6_addr *daddr)
{
return csum_ipv6_magic(saddr, daddr, skb->len, IPPROTO_DCCP, skb->csum);
}
Expand Down Expand Up @@ -87,7 +87,7 @@ static inline __u32 dccp_v6_init_sequence(struct sk_buff *skb)
static void dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
u8 type, u8 code, int offset, __be32 info)
{
struct ipv6hdr *hdr = (struct ipv6hdr *)skb->data;
const struct ipv6hdr *hdr = (const struct ipv6hdr *)skb->data;
const struct dccp_hdr *dh = (struct dccp_hdr *)(skb->data + offset);
struct dccp_sock *dp;
struct ipv6_pinfo *np;
Expand Down Expand Up @@ -296,7 +296,7 @@ static void dccp_v6_reqsk_destructor(struct request_sock *req)

static void dccp_v6_ctl_send_reset(struct sock *sk, struct sk_buff *rxskb)
{
struct ipv6hdr *rxip6h;
const struct ipv6hdr *rxip6h;
struct sk_buff *skb;
struct flowi6 fl6;
struct net *net = dev_net(skb_dst(rxskb)->dev);
Expand Down
4 changes: 2 additions & 2 deletions net/ipv4/af_inet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ EXPORT_SYMBOL(inet_sk_rebuild_header);

static int inet_gso_send_check(struct sk_buff *skb)
{
struct iphdr *iph;
const struct iphdr *iph;
const struct net_protocol *ops;
int proto;
int ihl;
Expand Down Expand Up @@ -1293,7 +1293,7 @@ static struct sk_buff **inet_gro_receive(struct sk_buff **head,
const struct net_protocol *ops;
struct sk_buff **pp = NULL;
struct sk_buff *p;
struct iphdr *iph;
const struct iphdr *iph;
unsigned int hlen;
unsigned int off;
unsigned int id;
Expand Down
7 changes: 4 additions & 3 deletions net/ipv4/ah4.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static inline struct scatterlist *ah_req_sg(struct crypto_ahash *ahash,
* into IP header for icv calculation. Options are already checked
* for validity, so paranoia is not required. */

static int ip_clear_mutable_options(struct iphdr *iph, __be32 *daddr)
static int ip_clear_mutable_options(const struct iphdr *iph, __be32 *daddr)
{
unsigned char * optptr = (unsigned char*)(iph+1);
int l = iph->ihl*4 - sizeof(struct iphdr);
Expand Down Expand Up @@ -396,15 +396,16 @@ static int ah_input(struct xfrm_state *x, struct sk_buff *skb)
static void ah4_err(struct sk_buff *skb, u32 info)
{
struct net *net = dev_net(skb->dev);
struct iphdr *iph = (struct iphdr *)skb->data;
const struct iphdr *iph = (const struct iphdr *)skb->data;
struct ip_auth_hdr *ah = (struct ip_auth_hdr *)(skb->data+(iph->ihl<<2));
struct xfrm_state *x;

if (icmp_hdr(skb)->type != ICMP_DEST_UNREACH ||
icmp_hdr(skb)->code != ICMP_FRAG_NEEDED)
return;

x = xfrm_state_lookup(net, skb->mark, (xfrm_address_t *)&iph->daddr, ah->spi, IPPROTO_AH, AF_INET);
x = xfrm_state_lookup(net, skb->mark, (const xfrm_address_t *)&iph->daddr,
ah->spi, IPPROTO_AH, AF_INET);
if (!x)
return;
printk(KERN_DEBUG "pmtu discovery on SA AH/%08x/%08x\n",
Expand Down
Loading

0 comments on commit b71d1d4

Please sign in to comment.