Skip to content

Commit 3d93657

Browse files
rlubosnashif
authored andcommitted
net: if: Add const qualifier to addr pointer where applicable
Some APIs taken in_addr/in6_addr pointer w/o const qualifier, while they do not actually intend to modify the provided address. This commit adds the missing const qualifier where applicable. Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
1 parent cb018ea commit 3d93657

File tree

3 files changed

+47
-45
lines changed

3 files changed

+47
-45
lines changed

include/zephyr/net/net_if.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,7 @@ struct net_if_addr *net_if_ipv6_addr_lookup_by_iface_raw(struct net_if *iface,
15531553
* @return Pointer to interface address, NULL if not found.
15541554
*/
15551555
struct net_if_addr *net_if_ipv6_addr_lookup_by_iface(struct net_if *iface,
1556-
struct in6_addr *addr);
1556+
const struct in6_addr *addr);
15571557

15581558
/**
15591559
* @brief Check if this IPv6 address belongs to one of the interface indices.
@@ -1576,7 +1576,7 @@ __syscall int net_if_ipv6_addr_lookup_by_index(const struct in6_addr *addr);
15761576
* @return Pointer to interface address, NULL if cannot be added
15771577
*/
15781578
struct net_if_addr *net_if_ipv6_addr_add(struct net_if *iface,
1579-
struct in6_addr *addr,
1579+
const struct in6_addr *addr,
15801580
enum net_addr_type addr_type,
15811581
uint32_t vlifetime);
15821582

@@ -1591,7 +1591,7 @@ struct net_if_addr *net_if_ipv6_addr_add(struct net_if *iface,
15911591
* @return True if ok, false if address could not be added
15921592
*/
15931593
__syscall bool net_if_ipv6_addr_add_by_index(int index,
1594-
struct in6_addr *addr,
1594+
const struct in6_addr *addr,
15951595
enum net_addr_type addr_type,
15961596
uint32_t vlifetime);
15971597

@@ -1828,7 +1828,7 @@ struct net_if_ipv6_prefix *net_if_ipv6_prefix_get(struct net_if *iface,
18281828
* @return Pointer to prefix, NULL if not found.
18291829
*/
18301830
struct net_if_ipv6_prefix *net_if_ipv6_prefix_lookup(struct net_if *iface,
1831-
struct in6_addr *addr,
1831+
const struct in6_addr *addr,
18321832
uint8_t len);
18331833

18341834
/**
@@ -1842,7 +1842,7 @@ struct net_if_ipv6_prefix *net_if_ipv6_prefix_lookup(struct net_if *iface,
18421842
* @return Pointer to prefix, NULL if the prefix was not added.
18431843
*/
18441844
struct net_if_ipv6_prefix *net_if_ipv6_prefix_add(struct net_if *iface,
1845-
struct in6_addr *prefix,
1845+
const struct in6_addr *prefix,
18461846
uint8_t len,
18471847
uint32_t lifetime);
18481848

@@ -1855,7 +1855,7 @@ struct net_if_ipv6_prefix *net_if_ipv6_prefix_add(struct net_if *iface,
18551855
*
18561856
* @return True if successfully removed, false otherwise
18571857
*/
1858-
bool net_if_ipv6_prefix_rm(struct net_if *iface, struct in6_addr *addr,
1858+
bool net_if_ipv6_prefix_rm(struct net_if *iface, const struct in6_addr *addr,
18591859
uint8_t len);
18601860

18611861
/**
@@ -1896,7 +1896,7 @@ void net_if_ipv6_prefix_unset_timer(struct net_if_ipv6_prefix *prefix);
18961896
*
18971897
* @return True if address is part of our subnet, false otherwise
18981898
*/
1899-
bool net_if_ipv6_addr_onlink(struct net_if **iface, struct in6_addr *addr);
1899+
bool net_if_ipv6_addr_onlink(struct net_if **iface, const struct in6_addr *addr);
19001900

19011901
/**
19021902
* @brief Get the IPv6 address of the given router
@@ -1934,7 +1934,7 @@ static inline struct in6_addr *net_if_router_ipv6(struct net_if_router *router)
19341934
* @return Pointer to router information, NULL if cannot be found
19351935
*/
19361936
struct net_if_router *net_if_ipv6_router_lookup(struct net_if *iface,
1937-
struct in6_addr *addr);
1937+
const struct in6_addr *addr);
19381938

19391939
/**
19401940
* @brief Find default router for this IPv6 address.
@@ -1946,7 +1946,7 @@ struct net_if_router *net_if_ipv6_router_lookup(struct net_if *iface,
19461946
* @return Pointer to router information, NULL if cannot be found
19471947
*/
19481948
struct net_if_router *net_if_ipv6_router_find_default(struct net_if *iface,
1949-
struct in6_addr *addr);
1949+
const struct in6_addr *addr);
19501950

19511951
/**
19521952
* @brief Update validity lifetime time of a router.
@@ -1967,7 +1967,7 @@ void net_if_ipv6_router_update_lifetime(struct net_if_router *router,
19671967
* @return Pointer to router information, NULL if could not be added
19681968
*/
19691969
struct net_if_router *net_if_ipv6_router_add(struct net_if *iface,
1970-
struct in6_addr *addr,
1970+
const struct in6_addr *addr,
19711971
uint16_t router_lifetime);
19721972

19731973
/**
@@ -2421,7 +2421,7 @@ struct net_if_addr *net_if_ipv4_addr_lookup(const struct in_addr *addr,
24212421
* @return Pointer to interface address, NULL if cannot be added
24222422
*/
24232423
struct net_if_addr *net_if_ipv4_addr_add(struct net_if *iface,
2424-
struct in_addr *addr,
2424+
const struct in_addr *addr,
24252425
enum net_addr_type addr_type,
24262426
uint32_t vlifetime);
24272427

@@ -2456,7 +2456,7 @@ __syscall int net_if_ipv4_addr_lookup_by_index(const struct in_addr *addr);
24562456
* @return True if ok, false if the address could not be added
24572457
*/
24582458
__syscall bool net_if_ipv4_addr_add_by_index(int index,
2459-
struct in_addr *addr,
2459+
const struct in_addr *addr,
24602460
enum net_addr_type addr_type,
24612461
uint32_t vlifetime);
24622462

@@ -2597,7 +2597,7 @@ static inline struct in_addr *net_if_router_ipv4(struct net_if_router *router)
25972597
* @return Pointer to router information, NULL if cannot be found
25982598
*/
25992599
struct net_if_router *net_if_ipv4_router_lookup(struct net_if *iface,
2600-
struct in_addr *addr);
2600+
const struct in_addr *addr);
26012601

26022602
/**
26032603
* @brief Find default router for this IPv4 address.
@@ -2609,7 +2609,7 @@ struct net_if_router *net_if_ipv4_router_lookup(struct net_if *iface,
26092609
* @return Pointer to router information, NULL if cannot be found
26102610
*/
26112611
struct net_if_router *net_if_ipv4_router_find_default(struct net_if *iface,
2612-
struct in_addr *addr);
2612+
const struct in_addr *addr);
26132613
/**
26142614
* @brief Add IPv4 router to the system.
26152615
*
@@ -2621,7 +2621,7 @@ struct net_if_router *net_if_ipv4_router_find_default(struct net_if *iface,
26212621
* @return Pointer to router information, NULL if could not be added
26222622
*/
26232623
struct net_if_router *net_if_ipv4_router_add(struct net_if *iface,
2624-
struct in_addr *addr,
2624+
const struct in_addr *addr,
26252625
bool is_default,
26262626
uint16_t router_lifetime);
26272627

include/zephyr/net/net_ip.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ static inline bool net_ipv6_is_addr_loopback_raw(const uint8_t *addr)
692692
*
693693
* @return True if address is a loopback address, False otherwise.
694694
*/
695-
static inline bool net_ipv6_is_addr_loopback(struct in6_addr *addr)
695+
static inline bool net_ipv6_is_addr_loopback(const struct in6_addr *addr)
696696
{
697697
return net_ipv6_is_addr_loopback_raw(addr->s6_addr);
698698
}
@@ -845,7 +845,7 @@ static inline bool net_ipv4_is_addr_loopback_raw(const uint8_t *addr)
845845
*
846846
* @return True if address is a loopback address, False otherwise.
847847
*/
848-
static inline bool net_ipv4_is_addr_loopback(struct in_addr *addr)
848+
static inline bool net_ipv4_is_addr_loopback(const struct in_addr *addr)
849849
{
850850
return net_ipv4_is_addr_loopback_raw(addr->s4_addr);
851851
}

subsys/net/ip/net_if.c

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,8 @@ static uint8_t get_ipaddr_diff(const uint8_t *src, const uint8_t *dst, int addr_
719719

720720
#if defined(CONFIG_NET_NATIVE_IPV4) || defined(CONFIG_NET_NATIVE_IPV6)
721721
static struct net_if_router *iface_router_lookup(struct net_if *iface,
722-
uint8_t family, void *addr)
722+
uint8_t family,
723+
const void *addr)
723724
{
724725
struct net_if_router *router = NULL;
725726
int i;
@@ -735,10 +736,10 @@ static struct net_if_router *iface_router_lookup(struct net_if *iface,
735736

736737
if ((IS_ENABLED(CONFIG_NET_IPV6) && family == AF_INET6 &&
737738
net_ipv6_addr_cmp(net_if_router_ipv6(&routers[i]),
738-
(struct in6_addr *)addr)) ||
739+
(const struct in6_addr *)addr)) ||
739740
(IS_ENABLED(CONFIG_NET_IPV4) && family == AF_INET &&
740741
net_ipv4_addr_cmp(net_if_router_ipv4(&routers[i]),
741-
(struct in_addr *)addr))) {
742+
(const struct in_addr *)addr))) {
742743
router = &routers[i];
743744
goto out;
744745
}
@@ -849,7 +850,7 @@ static void iface_router_expired(struct k_work *work)
849850
}
850851

851852
static struct net_if_router *iface_router_add(struct net_if *iface,
852-
uint8_t family, void *addr,
853+
uint8_t family, const void *addr,
853854
bool is_default,
854855
uint16_t lifetime)
855856
{
@@ -959,7 +960,8 @@ void net_if_router_rm(struct net_if_router *router)
959960
}
960961

961962
static struct net_if_router *iface_router_find_default(struct net_if *iface,
962-
uint8_t family, void *addr)
963+
uint8_t family,
964+
const void *addr)
963965
{
964966
struct net_if_router *router = NULL;
965967
int i;
@@ -1909,7 +1911,7 @@ struct net_if_addr *net_if_ipv6_addr_lookup_by_iface_raw(struct net_if *iface,
19091911
}
19101912

19111913
struct net_if_addr *net_if_ipv6_addr_lookup_by_iface(struct net_if *iface,
1912-
struct in6_addr *addr)
1914+
const struct in6_addr *addr)
19131915
{
19141916
return net_if_ipv6_addr_lookup_by_iface_raw(iface, addr->s6_addr);
19151917
}
@@ -1957,7 +1959,7 @@ void net_if_ipv6_addr_update_lifetime(struct net_if_addr *ifaddr,
19571959
}
19581960

19591961
static struct net_if_addr *ipv6_addr_find(struct net_if *iface,
1960-
struct in6_addr *addr)
1962+
const struct in6_addr *addr)
19611963
{
19621964
struct net_if_ipv6 *ipv6 = iface->config.ip.ipv6;
19631965

@@ -1977,7 +1979,7 @@ static struct net_if_addr *ipv6_addr_find(struct net_if *iface,
19771979
}
19781980

19791981
static inline void net_if_addr_init(struct net_if_addr *ifaddr,
1980-
struct in6_addr *addr,
1982+
const struct in6_addr *addr,
19811983
enum net_addr_type addr_type,
19821984
uint32_t vlifetime)
19831985
{
@@ -2006,7 +2008,7 @@ static inline void net_if_addr_init(struct net_if_addr *ifaddr,
20062008
}
20072009

20082010
struct net_if_addr *net_if_ipv6_addr_add(struct net_if *iface,
2009-
struct in6_addr *addr,
2011+
const struct in6_addr *addr,
20102012
enum net_addr_type addr_type,
20112013
uint32_t vlifetime)
20122014
{
@@ -2135,7 +2137,7 @@ bool net_if_ipv6_addr_rm(struct net_if *iface, const struct in6_addr *addr)
21352137
}
21362138

21372139
bool z_impl_net_if_ipv6_addr_add_by_index(int index,
2138-
struct in6_addr *addr,
2140+
const struct in6_addr *addr,
21392141
enum net_addr_type addr_type,
21402142
uint32_t vlifetime)
21412143
{
@@ -2152,7 +2154,7 @@ bool z_impl_net_if_ipv6_addr_add_by_index(int index,
21522154

21532155
#ifdef CONFIG_USERSPACE
21542156
bool z_vrfy_net_if_ipv6_addr_add_by_index(int index,
2155-
struct in6_addr *addr,
2157+
const struct in6_addr *addr,
21562158
enum net_addr_type addr_type,
21572159
uint32_t vlifetime)
21582160
{
@@ -2550,7 +2552,7 @@ struct in6_addr *net_if_ipv6_get_global_addr(enum net_addr_state state,
25502552
#if defined(CONFIG_NET_NATIVE_IPV6)
25512553
static void remove_prefix_addresses(struct net_if *iface,
25522554
struct net_if_ipv6 *ipv6,
2553-
struct in6_addr *addr,
2555+
const struct in6_addr *addr,
25542556
uint8_t len)
25552557
{
25562558
ARRAY_FOR_EACH(ipv6->unicast, i) {
@@ -2690,7 +2692,7 @@ static void prefix_start_timer(struct net_if_ipv6_prefix *ifprefix,
26902692
}
26912693

26922694
static struct net_if_ipv6_prefix *ipv6_prefix_find(struct net_if *iface,
2693-
struct in6_addr *prefix,
2695+
const struct in6_addr *prefix,
26942696
uint8_t prefix_len)
26952697
{
26962698
struct net_if_ipv6 *ipv6 = iface->config.ip.ipv6;
@@ -2715,7 +2717,7 @@ static struct net_if_ipv6_prefix *ipv6_prefix_find(struct net_if *iface,
27152717

27162718
static void net_if_ipv6_prefix_init(struct net_if *iface,
27172719
struct net_if_ipv6_prefix *ifprefix,
2718-
struct in6_addr *addr, uint8_t len,
2720+
const struct in6_addr *addr, uint8_t len,
27192721
uint32_t lifetime)
27202722
{
27212723
ifprefix->is_used = true;
@@ -2731,7 +2733,7 @@ static void net_if_ipv6_prefix_init(struct net_if *iface,
27312733
}
27322734

27332735
struct net_if_ipv6_prefix *net_if_ipv6_prefix_add(struct net_if *iface,
2734-
struct in6_addr *prefix,
2736+
const struct in6_addr *prefix,
27352737
uint8_t len,
27362738
uint32_t lifetime)
27372739
{
@@ -2788,7 +2790,7 @@ struct net_if_ipv6_prefix *net_if_ipv6_prefix_add(struct net_if *iface,
27882790
return ifprefix;
27892791
}
27902792

2791-
bool net_if_ipv6_prefix_rm(struct net_if *iface, struct in6_addr *addr,
2793+
bool net_if_ipv6_prefix_rm(struct net_if *iface, const struct in6_addr *addr,
27922794
uint8_t len)
27932795
{
27942796
bool ret = false;
@@ -2896,7 +2898,7 @@ struct net_if_ipv6_prefix *net_if_ipv6_prefix_get(struct net_if *iface,
28962898
}
28972899

28982900
struct net_if_ipv6_prefix *net_if_ipv6_prefix_lookup(struct net_if *iface,
2899-
struct in6_addr *addr,
2901+
const struct in6_addr *addr,
29002902
uint8_t len)
29012903
{
29022904
struct net_if_ipv6_prefix *prefix = NULL;
@@ -2927,7 +2929,7 @@ struct net_if_ipv6_prefix *net_if_ipv6_prefix_lookup(struct net_if *iface,
29272929
return prefix;
29282930
}
29292931

2930-
bool net_if_ipv6_addr_onlink(struct net_if **iface, struct in6_addr *addr)
2932+
bool net_if_ipv6_addr_onlink(struct net_if **iface, const struct in6_addr *addr)
29312933
{
29322934
bool ret = false;
29332935

@@ -2991,13 +2993,13 @@ void net_if_ipv6_prefix_unset_timer(struct net_if_ipv6_prefix *prefix)
29912993
}
29922994

29932995
struct net_if_router *net_if_ipv6_router_lookup(struct net_if *iface,
2994-
struct in6_addr *addr)
2996+
const struct in6_addr *addr)
29952997
{
29962998
return iface_router_lookup(iface, AF_INET6, addr);
29972999
}
29983000

29993001
struct net_if_router *net_if_ipv6_router_find_default(struct net_if *iface,
3000-
struct in6_addr *addr)
3002+
const struct in6_addr *addr)
30013003
{
30023004
return iface_router_find_default(iface, AF_INET6, addr);
30033005
}
@@ -3016,7 +3018,7 @@ void net_if_ipv6_router_update_lifetime(struct net_if_router *router,
30163018
}
30173019

30183020
struct net_if_router *net_if_ipv6_router_add(struct net_if *iface,
3019-
struct in6_addr *addr,
3021+
const struct in6_addr *addr,
30203022
uint16_t lifetime)
30213023
{
30223024
return iface_router_add(iface, AF_INET6, addr, false, lifetime);
@@ -4377,7 +4379,7 @@ bool z_vrfy_net_if_ipv4_set_gw_by_index(int index,
43774379
#endif /* CONFIG_USERSPACE */
43784380

43794381
static struct net_if_addr *ipv4_addr_find(struct net_if *iface,
4380-
struct in_addr *addr)
4382+
const struct in_addr *addr)
43814383
{
43824384
struct net_if_ipv4 *ipv4 = iface->config.ip.ipv4;
43834385

@@ -4526,7 +4528,7 @@ void net_if_start_acd(struct net_if *iface)
45264528
#endif /* CONFIG_NET_IPV4_ACD */
45274529

45284530
struct net_if_addr *net_if_ipv4_addr_add(struct net_if *iface,
4529-
struct in_addr *addr,
4531+
const struct in_addr *addr,
45304532
enum net_addr_type addr_type,
45314533
uint32_t vlifetime)
45324534
{
@@ -4671,7 +4673,7 @@ bool net_if_ipv4_addr_rm(struct net_if *iface, const struct in_addr *addr)
46714673
}
46724674

46734675
bool z_impl_net_if_ipv4_addr_add_by_index(int index,
4674-
struct in_addr *addr,
4676+
const struct in_addr *addr,
46754677
enum net_addr_type addr_type,
46764678
uint32_t vlifetime)
46774679
{
@@ -4689,7 +4691,7 @@ bool z_impl_net_if_ipv4_addr_add_by_index(int index,
46894691

46904692
#ifdef CONFIG_USERSPACE
46914693
bool z_vrfy_net_if_ipv4_addr_add_by_index(int index,
4692-
struct in_addr *addr,
4694+
const struct in_addr *addr,
46934695
enum net_addr_type addr_type,
46944696
uint32_t vlifetime)
46954697
{
@@ -5027,19 +5029,19 @@ void net_if_ipv4_set_mcast_ttl(struct net_if *iface, uint8_t ttl)
50275029
}
50285030

50295031
struct net_if_router *net_if_ipv4_router_lookup(struct net_if *iface,
5030-
struct in_addr *addr)
5032+
const struct in_addr *addr)
50315033
{
50325034
return iface_router_lookup(iface, AF_INET, addr);
50335035
}
50345036

50355037
struct net_if_router *net_if_ipv4_router_find_default(struct net_if *iface,
5036-
struct in_addr *addr)
5038+
const struct in_addr *addr)
50375039
{
50385040
return iface_router_find_default(iface, AF_INET, addr);
50395041
}
50405042

50415043
struct net_if_router *net_if_ipv4_router_add(struct net_if *iface,
5042-
struct in_addr *addr,
5044+
const struct in_addr *addr,
50435045
bool is_default,
50445046
uint16_t lifetime)
50455047
{

0 commit comments

Comments
 (0)