Skip to content

Commit b71d1d4

Browse files
Eric Dumazetdavem330
authored andcommitted
inet: constify ip headers and in6_addr
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]>
1 parent 5f8629c commit b71d1d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+316
-310
lines changed

include/net/addrconf.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ extern int addrconf_set_dstaddr(struct net *net,
6161
void __user *arg);
6262

6363
extern int ipv6_chk_addr(struct net *net,
64-
struct in6_addr *addr,
64+
const struct in6_addr *addr,
6565
struct net_device *dev,
6666
int strict);
6767

6868
#if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
6969
extern int ipv6_chk_home_addr(struct net *net,
70-
struct in6_addr *addr);
70+
const struct in6_addr *addr);
7171
#endif
7272

73-
extern int ipv6_chk_prefix(struct in6_addr *addr,
73+
extern int ipv6_chk_prefix(const struct in6_addr *addr,
7474
struct net_device *dev);
7575

7676
extern struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net,
@@ -89,9 +89,9 @@ extern int ipv6_get_lladdr(struct net_device *dev,
8989
extern int ipv6_rcv_saddr_equal(const struct sock *sk,
9090
const struct sock *sk2);
9191
extern void addrconf_join_solict(struct net_device *dev,
92-
struct in6_addr *addr);
92+
const struct in6_addr *addr);
9393
extern void addrconf_leave_solict(struct inet6_dev *idev,
94-
struct in6_addr *addr);
94+
const struct in6_addr *addr);
9595

9696
static inline unsigned long addrconf_timeout_fixup(u32 timeout,
9797
unsigned unit)
@@ -158,15 +158,15 @@ extern void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len);
158158
/*
159159
* anycast prototypes (anycast.c)
160160
*/
161-
extern int ipv6_sock_ac_join(struct sock *sk,int ifindex,struct in6_addr *addr);
162-
extern int ipv6_sock_ac_drop(struct sock *sk,int ifindex,struct in6_addr *addr);
161+
extern int ipv6_sock_ac_join(struct sock *sk,int ifindex, const struct in6_addr *addr);
162+
extern int ipv6_sock_ac_drop(struct sock *sk,int ifindex, const struct in6_addr *addr);
163163
extern void ipv6_sock_ac_close(struct sock *sk);
164-
extern int inet6_ac_check(struct sock *sk, struct in6_addr *addr, int ifindex);
164+
extern int inet6_ac_check(struct sock *sk, const struct in6_addr *addr, int ifindex);
165165

166-
extern int ipv6_dev_ac_inc(struct net_device *dev, struct in6_addr *addr);
167-
extern int __ipv6_dev_ac_dec(struct inet6_dev *idev, struct in6_addr *addr);
166+
extern int ipv6_dev_ac_inc(struct net_device *dev, const struct in6_addr *addr);
167+
extern int __ipv6_dev_ac_dec(struct inet6_dev *idev, const struct in6_addr *addr);
168168
extern int ipv6_chk_acast_addr(struct net *net, struct net_device *dev,
169-
struct in6_addr *addr);
169+
const struct in6_addr *addr);
170170

171171

172172
/* Device notifier */

include/net/if_inet6.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ struct inet6_dev {
196196
struct rcu_head rcu;
197197
};
198198

199-
static inline void ipv6_eth_mc_map(struct in6_addr *addr, char *buf)
199+
static inline void ipv6_eth_mc_map(const struct in6_addr *addr, char *buf)
200200
{
201201
/*
202202
* +-------+-------+-------+-------+-------+-------+
@@ -210,7 +210,7 @@ static inline void ipv6_eth_mc_map(struct in6_addr *addr, char *buf)
210210
memcpy(buf + 2, &addr->s6_addr32[3], sizeof(__u32));
211211
}
212212

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

include/net/inetpeer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static inline struct inet_peer *inet_getpeer_v4(__be32 v4daddr, int create)
8080
return inet_getpeer(&daddr, create);
8181
}
8282

83-
static inline struct inet_peer *inet_getpeer_v6(struct in6_addr *v6daddr, int create)
83+
static inline struct inet_peer *inet_getpeer_v6(const struct in6_addr *v6daddr, int create)
8484
{
8585
struct inetpeer_addr daddr;
8686

include/net/ip6_fib.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,12 @@ extern struct dst_entry *fib6_rule_lookup(struct net *net,
198198
pol_lookup_t lookup);
199199

200200
extern struct fib6_node *fib6_lookup(struct fib6_node *root,
201-
struct in6_addr *daddr,
202-
struct in6_addr *saddr);
201+
const struct in6_addr *daddr,
202+
const struct in6_addr *saddr);
203203

204204
struct fib6_node *fib6_locate(struct fib6_node *root,
205-
struct in6_addr *daddr, int dst_len,
206-
struct in6_addr *saddr, int src_len);
205+
const struct in6_addr *daddr, int dst_len,
206+
const struct in6_addr *saddr, int src_len);
207207

208208
extern void fib6_clean_all(struct net *net,
209209
int (*func)(struct rt6_info *, void *arg),

include/net/ip6_route.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ extern int ip6_del_rt(struct rt6_info *);
8686

8787
extern int ip6_route_get_saddr(struct net *net,
8888
struct rt6_info *rt,
89-
struct in6_addr *daddr,
89+
const struct in6_addr *daddr,
9090
unsigned int prefs,
9191
struct in6_addr *saddr);
9292

@@ -112,27 +112,27 @@ extern int ip6_dst_hoplimit(struct dst_entry *dst);
112112
* support functions for ND
113113
*
114114
*/
115-
extern struct rt6_info * rt6_get_dflt_router(struct in6_addr *addr,
115+
extern struct rt6_info * rt6_get_dflt_router(const struct in6_addr *addr,
116116
struct net_device *dev);
117-
extern struct rt6_info * rt6_add_dflt_router(struct in6_addr *gwaddr,
117+
extern struct rt6_info * rt6_add_dflt_router(const struct in6_addr *gwaddr,
118118
struct net_device *dev,
119119
unsigned int pref);
120120

121121
extern void rt6_purge_dflt_routers(struct net *net);
122122

123123
extern int rt6_route_rcv(struct net_device *dev,
124124
u8 *opt, int len,
125-
struct in6_addr *gwaddr);
125+
const struct in6_addr *gwaddr);
126126

127-
extern void rt6_redirect(struct in6_addr *dest,
128-
struct in6_addr *src,
129-
struct in6_addr *saddr,
127+
extern void rt6_redirect(const struct in6_addr *dest,
128+
const struct in6_addr *src,
129+
const struct in6_addr *saddr,
130130
struct neighbour *neigh,
131131
u8 *lladdr,
132132
int on_link);
133133

134-
extern void rt6_pmtu_discovery(struct in6_addr *daddr,
135-
struct in6_addr *saddr,
134+
extern void rt6_pmtu_discovery(const struct in6_addr *daddr,
135+
const struct in6_addr *saddr,
136136
struct net_device *dev,
137137
u32 pmtu);
138138

include/net/ipv6.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,8 @@ enum ip6_defrag_users {
376376
struct ip6_create_arg {
377377
__be32 id;
378378
u32 user;
379-
struct in6_addr *src;
380-
struct in6_addr *dst;
379+
const struct in6_addr *src;
380+
const struct in6_addr *dst;
381381
};
382382

383383
void ip6_frag_init(struct inet_frag_queue *q, void *a);

include/net/ndisc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ extern void ndisc_send_redirect(struct sk_buff *skb,
102102
struct neighbour *neigh,
103103
const struct in6_addr *target);
104104

105-
extern int ndisc_mc_map(struct in6_addr *addr, char *buf, struct net_device *dev, int dir);
105+
extern int ndisc_mc_map(const struct in6_addr *addr, char *buf,
106+
struct net_device *dev, int dir);
106107

107108
extern struct sk_buff *ndisc_build_skb(struct net_device *dev,
108109
const struct in6_addr *daddr,

include/net/route.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ static inline int ip_route_input_noref(struct sk_buff *skb, __be32 dst, __be32 s
191191
return ip_route_input_common(skb, dst, src, tos, devin, true);
192192
}
193193

194-
extern unsigned short ip_rt_frag_needed(struct net *net, struct iphdr *iph, unsigned short new_mtu, struct net_device *dev);
194+
extern unsigned short ip_rt_frag_needed(struct net *net, const struct iphdr *iph,
195+
unsigned short new_mtu, struct net_device *dev);
195196
extern void ip_rt_send_redirect(struct sk_buff *skb);
196197

197198
extern unsigned inet_addr_type(struct net *net, __be32 addr);

include/net/xfrm.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,7 @@ extern int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr,
14751475
extern int xfrm6_tunnel_register(struct xfrm6_tunnel *handler, unsigned short family);
14761476
extern int xfrm6_tunnel_deregister(struct xfrm6_tunnel *handler, unsigned short family);
14771477
extern __be32 xfrm6_tunnel_alloc_spi(struct net *net, xfrm_address_t *saddr);
1478-
extern __be32 xfrm6_tunnel_spi_lookup(struct net *net, xfrm_address_t *saddr);
1478+
extern __be32 xfrm6_tunnel_spi_lookup(struct net *net, const xfrm_address_t *saddr);
14791479
extern int xfrm6_extract_output(struct xfrm_state *x, struct sk_buff *skb);
14801480
extern int xfrm6_prepare_output(struct xfrm_state *x, struct sk_buff *skb);
14811481
extern int xfrm6_output(struct sk_buff *skb);
@@ -1569,8 +1569,8 @@ static inline int xfrm_addr_cmp(const xfrm_address_t *a,
15691569
case AF_INET:
15701570
return (__force u32)a->a4 - (__force u32)b->a4;
15711571
case AF_INET6:
1572-
return ipv6_addr_cmp((struct in6_addr *)a,
1573-
(struct in6_addr *)b);
1572+
return ipv6_addr_cmp((const struct in6_addr *)a,
1573+
(const struct in6_addr *)b);
15741574
}
15751575
}
15761576

net/bridge/br_multicast.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ static struct sk_buff *br_ip4_multicast_alloc_query(struct net_bridge *br,
413413

414414
#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
415415
static struct sk_buff *br_ip6_multicast_alloc_query(struct net_bridge *br,
416-
struct in6_addr *group)
416+
const struct in6_addr *group)
417417
{
418418
struct sk_buff *skb;
419419
struct ipv6hdr *ip6h;
@@ -1115,7 +1115,7 @@ static int br_ip4_multicast_query(struct net_bridge *br,
11151115
struct net_bridge_port *port,
11161116
struct sk_buff *skb)
11171117
{
1118-
struct iphdr *iph = ip_hdr(skb);
1118+
const struct iphdr *iph = ip_hdr(skb);
11191119
struct igmphdr *ih = igmp_hdr(skb);
11201120
struct net_bridge_mdb_entry *mp;
11211121
struct igmpv3_query *ih3;
@@ -1190,15 +1190,15 @@ static int br_ip6_multicast_query(struct net_bridge *br,
11901190
struct net_bridge_port *port,
11911191
struct sk_buff *skb)
11921192
{
1193-
struct ipv6hdr *ip6h = ipv6_hdr(skb);
1193+
const struct ipv6hdr *ip6h = ipv6_hdr(skb);
11941194
struct mld_msg *mld = (struct mld_msg *) icmp6_hdr(skb);
11951195
struct net_bridge_mdb_entry *mp;
11961196
struct mld2_query *mld2q;
11971197
struct net_bridge_port_group *p;
11981198
struct net_bridge_port_group __rcu **pp;
11991199
unsigned long max_delay;
12001200
unsigned long now = jiffies;
1201-
struct in6_addr *group = NULL;
1201+
const struct in6_addr *group = NULL;
12021202
int err = 0;
12031203

12041204
spin_lock(&br->multicast_lock);
@@ -1356,7 +1356,7 @@ static int br_multicast_ipv4_rcv(struct net_bridge *br,
13561356
struct sk_buff *skb)
13571357
{
13581358
struct sk_buff *skb2 = skb;
1359-
struct iphdr *iph;
1359+
const struct iphdr *iph;
13601360
struct igmphdr *ih;
13611361
unsigned len;
13621362
unsigned offset;
@@ -1452,7 +1452,7 @@ static int br_multicast_ipv6_rcv(struct net_bridge *br,
14521452
struct sk_buff *skb)
14531453
{
14541454
struct sk_buff *skb2;
1455-
struct ipv6hdr *ip6h;
1455+
const struct ipv6hdr *ip6h;
14561456
struct icmp6hdr *icmp6h;
14571457
u8 nexthdr;
14581458
unsigned len;

net/bridge/br_netfilter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ static inline void nf_bridge_update_protocol(struct sk_buff *skb)
219219
static int br_parse_ip_options(struct sk_buff *skb)
220220
{
221221
struct ip_options *opt;
222-
struct iphdr *iph;
222+
const struct iphdr *iph;
223223
struct net_device *dev = skb->dev;
224224
u32 len;
225225

@@ -554,7 +554,7 @@ static unsigned int br_nf_pre_routing_ipv6(unsigned int hook,
554554
const struct net_device *out,
555555
int (*okfn)(struct sk_buff *))
556556
{
557-
struct ipv6hdr *hdr;
557+
const struct ipv6hdr *hdr;
558558
u32 pkt_len;
559559

560560
if (skb->len < sizeof(struct ipv6hdr))

net/core/dev.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2502,8 +2502,8 @@ static inline void ____napi_schedule(struct softnet_data *sd,
25022502
__u32 __skb_get_rxhash(struct sk_buff *skb)
25032503
{
25042504
int nhoff, hash = 0, poff;
2505-
struct ipv6hdr *ip6;
2506-
struct iphdr *ip;
2505+
const struct ipv6hdr *ip6;
2506+
const struct iphdr *ip;
25072507
u8 ip_proto;
25082508
u32 addr1, addr2, ihl;
25092509
union {
@@ -2518,7 +2518,7 @@ __u32 __skb_get_rxhash(struct sk_buff *skb)
25182518
if (!pskb_may_pull(skb, sizeof(*ip) + nhoff))
25192519
goto done;
25202520

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

2534-
ip6 = (struct ipv6hdr *) (skb->data + nhoff);
2534+
ip6 = (const struct ipv6hdr *) (skb->data + nhoff);
25352535
ip_proto = ip6->nexthdr;
25362536
addr1 = (__force u32) ip6->saddr.s6_addr32[3];
25372537
addr2 = (__force u32) ip6->daddr.s6_addr32[3];

net/core/netpoll.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ int __netpoll_rx(struct sk_buff *skb)
539539
{
540540
int proto, len, ulen;
541541
int hits = 0;
542-
struct iphdr *iph;
542+
const struct iphdr *iph;
543543
struct udphdr *uh;
544544
struct netpoll_info *npinfo = skb->dev->npinfo;
545545
struct netpoll *np, *tmp;

net/dccp/ipv6.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ static void dccp_v6_hash(struct sock *sk)
5454

5555
/* add pseudo-header to DCCP checksum stored in skb->csum */
5656
static inline __sum16 dccp_v6_csum_finish(struct sk_buff *skb,
57-
struct in6_addr *saddr,
58-
struct in6_addr *daddr)
57+
const struct in6_addr *saddr,
58+
const struct in6_addr *daddr)
5959
{
6060
return csum_ipv6_magic(saddr, daddr, skb->len, IPPROTO_DCCP, skb->csum);
6161
}
@@ -87,7 +87,7 @@ static inline __u32 dccp_v6_init_sequence(struct sk_buff *skb)
8787
static void dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
8888
u8 type, u8 code, int offset, __be32 info)
8989
{
90-
struct ipv6hdr *hdr = (struct ipv6hdr *)skb->data;
90+
const struct ipv6hdr *hdr = (const struct ipv6hdr *)skb->data;
9191
const struct dccp_hdr *dh = (struct dccp_hdr *)(skb->data + offset);
9292
struct dccp_sock *dp;
9393
struct ipv6_pinfo *np;
@@ -296,7 +296,7 @@ static void dccp_v6_reqsk_destructor(struct request_sock *req)
296296

297297
static void dccp_v6_ctl_send_reset(struct sock *sk, struct sk_buff *rxskb)
298298
{
299-
struct ipv6hdr *rxip6h;
299+
const struct ipv6hdr *rxip6h;
300300
struct sk_buff *skb;
301301
struct flowi6 fl6;
302302
struct net *net = dev_net(skb_dst(rxskb)->dev);

net/ipv4/af_inet.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ EXPORT_SYMBOL(inet_sk_rebuild_header);
11861186

11871187
static int inet_gso_send_check(struct sk_buff *skb)
11881188
{
1189-
struct iphdr *iph;
1189+
const struct iphdr *iph;
11901190
const struct net_protocol *ops;
11911191
int proto;
11921192
int ihl;
@@ -1293,7 +1293,7 @@ static struct sk_buff **inet_gro_receive(struct sk_buff **head,
12931293
const struct net_protocol *ops;
12941294
struct sk_buff **pp = NULL;
12951295
struct sk_buff *p;
1296-
struct iphdr *iph;
1296+
const struct iphdr *iph;
12971297
unsigned int hlen;
12981298
unsigned int off;
12991299
unsigned int id;

net/ipv4/ah4.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static inline struct scatterlist *ah_req_sg(struct crypto_ahash *ahash,
7373
* into IP header for icv calculation. Options are already checked
7474
* for validity, so paranoia is not required. */
7575

76-
static int ip_clear_mutable_options(struct iphdr *iph, __be32 *daddr)
76+
static int ip_clear_mutable_options(const struct iphdr *iph, __be32 *daddr)
7777
{
7878
unsigned char * optptr = (unsigned char*)(iph+1);
7979
int l = iph->ihl*4 - sizeof(struct iphdr);
@@ -396,15 +396,16 @@ static int ah_input(struct xfrm_state *x, struct sk_buff *skb)
396396
static void ah4_err(struct sk_buff *skb, u32 info)
397397
{
398398
struct net *net = dev_net(skb->dev);
399-
struct iphdr *iph = (struct iphdr *)skb->data;
399+
const struct iphdr *iph = (const struct iphdr *)skb->data;
400400
struct ip_auth_hdr *ah = (struct ip_auth_hdr *)(skb->data+(iph->ihl<<2));
401401
struct xfrm_state *x;
402402

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

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

0 commit comments

Comments
 (0)