Added the const keyword to IP address arguments that are not (and should not be) changed by the callee

This commit is contained in:
Adam Dunkels 2013-11-16 14:42:57 +01:00
parent 7b59e1dbe7
commit f9cb6ec2fa
12 changed files with 40 additions and 40 deletions

View file

@ -86,7 +86,7 @@ index_from_key(nbr_table_key_t *key)
/*---------------------------------------------------------------------------*/
/* Get the neighbor index of an item */
static int
index_from_item(nbr_table_t *table, nbr_table_item_t *item)
index_from_item(nbr_table_t *table, const nbr_table_item_t *item)
{
return table != NULL && item != NULL ? ((int)((char *)item - (char *)table->data)) / table->item_size : -1;
}
@ -100,7 +100,7 @@ item_from_key(nbr_table_t *table, nbr_table_key_t *key)
/*---------------------------------------------------------------------------*/
/* Get the key af an item */
static nbr_table_key_t *
key_from_item(nbr_table_t *table, nbr_table_item_t *item)
key_from_item(nbr_table_t *table, const nbr_table_item_t *item)
{
return key_from_index(index_from_item(table, item));
}
@ -343,7 +343,7 @@ nbr_table_unlock(nbr_table_t *table, void *item)
/*---------------------------------------------------------------------------*/
/* Get link-layer address of an item */
rimeaddr_t *
nbr_table_get_lladdr(nbr_table_t *table, void *item)
nbr_table_get_lladdr(nbr_table_t *table, const void *item)
{
nbr_table_key_t *key = key_from_item(table, item);
return key != NULL ? &key->lladdr : NULL;

View file

@ -97,7 +97,7 @@ int nbr_table_unlock(nbr_table_t *table, nbr_table_item_t *item);
/** \name Neighbor tables: address manipulation */
/** @{ */
rimeaddr_t *nbr_table_get_lladdr(nbr_table_t *table, nbr_table_item_t *item);
rimeaddr_t *nbr_table_get_lladdr(nbr_table_t *table, const nbr_table_item_t *item);
/** @} */
#endif /* _NBR_TABLE_H_ */

View file

@ -96,9 +96,9 @@ rpl_get_parent_rank(uip_lladdr_t *addr)
}
/*---------------------------------------------------------------------------*/
uint16_t
rpl_get_parent_link_metric(uip_lladdr_t *addr)
rpl_get_parent_link_metric(const uip_lladdr_t *addr)
{
rpl_parent_t *p = nbr_table_get_from_lladdr(rpl_parents, (rimeaddr_t *)addr);
rpl_parent_t *p = nbr_table_get_from_lladdr(rpl_parents, (const rimeaddr_t *)addr);
if(p != NULL) {
return p->link_metric;
} else {
@ -539,7 +539,7 @@ rpl_add_parent(rpl_dag_t *dag, rpl_dio_t *dio, uip_ipaddr_t *addr)
rpl_parent_t *p = NULL;
/* Is the parent known by ds6? Drop this request if not.
* Typically, the parent is added upon receiving a DIO. */
uip_lladdr_t *lladdr = uip_ds6_nbr_lladdr_from_ipaddr(addr);
const uip_lladdr_t *lladdr = uip_ds6_nbr_lladdr_from_ipaddr(addr);
PRINTF("RPL: rpl_add_parent lladdr %p\n", lladdr);
if(lladdr != NULL) {
@ -561,7 +561,7 @@ static rpl_parent_t *
find_parent_any_dag_any_instance(uip_ipaddr_t *addr)
{
uip_ds6_nbr_t *ds6_nbr = uip_ds6_nbr_lookup(addr);
uip_lladdr_t *lladdr = uip_ds6_nbr_get_ll(ds6_nbr);
const uip_lladdr_t *lladdr = uip_ds6_nbr_get_ll(ds6_nbr);
return nbr_table_get_from_lladdr(rpl_parents, (rimeaddr_t *)lladdr);
}
/*---------------------------------------------------------------------------*/

View file

@ -245,7 +245,7 @@ void rpl_remove_header(void);
uint8_t rpl_invert_header(void);
uip_ipaddr_t *rpl_get_parent_ipaddr(rpl_parent_t *nbr);
rpl_rank_t rpl_get_parent_rank(uip_lladdr_t *addr);
uint16_t rpl_get_parent_link_metric(uip_lladdr_t *addr);
uint16_t rpl_get_parent_link_metric(const uip_lladdr_t *addr);
void rpl_dag_init(void);
/*---------------------------------------------------------------------------*/
#endif /* RPL_H */

View file

@ -1354,7 +1354,7 @@ send_packet(rimeaddr_t *dest)
* MAC.
*/
static uint8_t
output(uip_lladdr_t *localdest)
output(const uip_lladdr_t *localdest)
{
int framer_hdrlen;

View file

@ -109,10 +109,10 @@ enum {
/* Called on IP packet output. */
#if UIP_CONF_IPV6
static uint8_t (* outputfunc)(uip_lladdr_t *a);
static uint8_t (* outputfunc)(const uip_lladdr_t *a);
uint8_t
tcpip_output(uip_lladdr_t *a)
tcpip_output(const uip_lladdr_t *a)
{
int ret;
if(outputfunc != NULL) {
@ -124,7 +124,7 @@ tcpip_output(uip_lladdr_t *a)
}
void
tcpip_set_outputfunc(uint8_t (*f)(uip_lladdr_t *))
tcpip_set_outputfunc(uint8_t (*f)(const uip_lladdr_t *))
{
outputfunc = f;
}

View file

@ -340,8 +340,8 @@ CCIF void tcpip_input(void);
* The eventual parameter is the MAC address of the destination.
*/
#if UIP_CONF_IPV6
uint8_t tcpip_output(uip_lladdr_t *);
void tcpip_set_outputfunc(uint8_t (* f)(uip_lladdr_t *));
uint8_t tcpip_output(const uip_lladdr_t *);
void tcpip_set_outputfunc(uint8_t (* f)(const uip_lladdr_t *));
#else
uint8_t tcpip_output(void);
void tcpip_set_outputfunc(uint8_t (* f)(void));

View file

@ -78,7 +78,7 @@ uip_ds6_neighbors_init(void)
}
/*---------------------------------------------------------------------------*/
uip_ds6_nbr_t *
uip_ds6_nbr_add(uip_ipaddr_t *ipaddr, uip_lladdr_t *lladdr,
uip_ds6_nbr_add(const uip_ipaddr_t *ipaddr, const uip_lladdr_t *lladdr,
uint8_t isrouter, uint8_t state)
{
uip_ds6_nbr_t *nbr = nbr_table_add_lladdr(ds6_neighbors, (rimeaddr_t*)lladdr);
@ -125,17 +125,17 @@ uip_ds6_nbr_rm(uip_ds6_nbr_t *nbr)
}
/*---------------------------------------------------------------------------*/
uip_ipaddr_t *
uip_ds6_nbr_get_ipaddr(uip_ds6_nbr_t *nbr)
const uip_ipaddr_t *
uip_ds6_nbr_get_ipaddr(const uip_ds6_nbr_t *nbr)
{
return (nbr != NULL) ? &nbr->ipaddr : NULL;
}
/*---------------------------------------------------------------------------*/
uip_lladdr_t *
uip_ds6_nbr_get_ll(uip_ds6_nbr_t *nbr)
const uip_lladdr_t *
uip_ds6_nbr_get_ll(const uip_ds6_nbr_t *nbr)
{
return (uip_lladdr_t *)nbr_table_get_lladdr(ds6_neighbors, nbr);
return (const uip_lladdr_t *)nbr_table_get_lladdr(ds6_neighbors, nbr);
}
/*---------------------------------------------------------------------------*/
int
@ -154,7 +154,7 @@ uip_ds6_nbr_num(void)
}
/*---------------------------------------------------------------------------*/
uip_ds6_nbr_t *
uip_ds6_nbr_lookup(uip_ipaddr_t *ipaddr)
uip_ds6_nbr_lookup(const uip_ipaddr_t *ipaddr)
{
uip_ds6_nbr_t *nbr = nbr_table_head(ds6_neighbors);
if(ipaddr != NULL) {
@ -169,22 +169,22 @@ uip_ds6_nbr_lookup(uip_ipaddr_t *ipaddr)
}
/*---------------------------------------------------------------------------*/
uip_ds6_nbr_t *
uip_ds6_nbr_ll_lookup(uip_lladdr_t *lladdr)
uip_ds6_nbr_ll_lookup(const uip_lladdr_t *lladdr)
{
return nbr_table_get_from_lladdr(ds6_neighbors, (rimeaddr_t*)lladdr);
}
/*---------------------------------------------------------------------------*/
uip_ipaddr_t *
uip_ds6_nbr_ipaddr_from_lladdr(uip_lladdr_t *lladdr)
uip_ds6_nbr_ipaddr_from_lladdr(const uip_lladdr_t *lladdr)
{
uip_ds6_nbr_t *nbr = uip_ds6_nbr_ll_lookup(lladdr);
return nbr ? &nbr->ipaddr : NULL;
}
/*---------------------------------------------------------------------------*/
uip_lladdr_t *
uip_ds6_nbr_lladdr_from_ipaddr(uip_ipaddr_t *ipaddr)
const uip_lladdr_t *
uip_ds6_nbr_lladdr_from_ipaddr(const uip_ipaddr_t *ipaddr)
{
uip_ds6_nbr_t *nbr = uip_ds6_nbr_lookup(ipaddr);
return nbr ? uip_ds6_nbr_get_ll(nbr) : NULL;
@ -276,7 +276,6 @@ uip_ds6_neighbor_periodic(void)
nbr = nbr_table_next(ds6_neighbors, nbr);
}
}
/*---------------------------------------------------------------------------*/
uip_ds6_nbr_t *
uip_ds6_get_least_lifetime_neighbor(void)
@ -296,3 +295,4 @@ uip_ds6_get_least_lifetime_neighbor(void)
}
return nbr_expiring;
}
/*---------------------------------------------------------------------------*/

View file

@ -83,15 +83,15 @@ typedef struct uip_ds6_nbr {
void uip_ds6_neighbors_init(void);
/** \brief Neighbor Cache basic routines */
uip_ds6_nbr_t *uip_ds6_nbr_add(uip_ipaddr_t *ipaddr, uip_lladdr_t *lladdr,
uip_ds6_nbr_t *uip_ds6_nbr_add(const uip_ipaddr_t *ipaddr, const uip_lladdr_t *lladdr,
uint8_t isrouter, uint8_t state);
void uip_ds6_nbr_rm(uip_ds6_nbr_t *nbr);
uip_lladdr_t *uip_ds6_nbr_get_ll(uip_ds6_nbr_t *nbr);
uip_ipaddr_t *uip_ds6_nbr_get_ipaddr(uip_ds6_nbr_t *nbr);
uip_ds6_nbr_t *uip_ds6_nbr_lookup(uip_ipaddr_t *ipaddr);
uip_ds6_nbr_t *uip_ds6_nbr_ll_lookup(uip_lladdr_t *lladdr);
uip_ipaddr_t *uip_ds6_nbr_ipaddr_from_lladdr(uip_lladdr_t *lladdr);
uip_lladdr_t *uip_ds6_nbr_lladdr_from_ipaddr(uip_ipaddr_t *ipaddr);
const uip_lladdr_t *uip_ds6_nbr_get_ll(const uip_ds6_nbr_t *nbr);
const uip_ipaddr_t *uip_ds6_nbr_get_ipaddr(const uip_ds6_nbr_t *nbr);
uip_ds6_nbr_t *uip_ds6_nbr_lookup(const uip_ipaddr_t *ipaddr);
uip_ds6_nbr_t *uip_ds6_nbr_ll_lookup(const uip_lladdr_t *lladdr);
uip_ipaddr_t *uip_ds6_nbr_ipaddr_from_lladdr(const uip_lladdr_t *lladdr);
const uip_lladdr_t *uip_ds6_nbr_lladdr_from_ipaddr(const uip_ipaddr_t *ipaddr);
void uip_ds6_link_neighbor_callback(int status, int numtx);
void uip_ds6_neighbor_periodic(void);
int uip_ds6_nbr_num(void);

View file

@ -261,7 +261,7 @@ uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length,
#endif /* DEBUG != DEBUG_NONE */
/* Get link-layer address of next hop, make sure it is in neighbor table */
uip_lladdr_t *nexthop_lladdr = uip_ds6_nbr_lladdr_from_ipaddr(nexthop);
const uip_lladdr_t *nexthop_lladdr = uip_ds6_nbr_lladdr_from_ipaddr(nexthop);
if(nexthop_lladdr == NULL) {
PRINTF("uip_ds6_route_add: neighbor link-local address unknown ");
PRINT6ADDR(ipaddr);
@ -440,7 +440,7 @@ void
uip_ds6_route_rm_by_nexthop(uip_ipaddr_t *nexthop)
{
/* Get routing entry list of this neighbor */
uip_lladdr_t *nexthop_lladdr;
const uip_lladdr_t *nexthop_lladdr;
struct uip_ds6_route_neighbor_routes *routes;
nexthop_lladdr = uip_ds6_nbr_lladdr_from_ipaddr(nexthop);

View file

@ -191,7 +191,7 @@ uip_nd6_ns_input(void)
(uip_lladdr_t *)&nd6_opt_llao[UIP_ND6_OPT_DATA_OFFSET],
0, NBR_STALE);
} else {
uip_lladdr_t *lladdr = uip_ds6_nbr_get_ll(nbr);
uip_lladdr_t *lladdr = (uip_lladdr_t *)uip_ds6_nbr_get_ll(nbr);
if(memcmp(&nd6_opt_llao[UIP_ND6_OPT_DATA_OFFSET],
lladdr, UIP_LLADDR_LEN) != 0) {
memcpy(lladdr, &nd6_opt_llao[UIP_ND6_OPT_DATA_OFFSET],
@ -463,7 +463,7 @@ uip_nd6_na_input(void)
} else {
uip_lladdr_t *lladdr;
nbr = uip_ds6_nbr_lookup(&UIP_ND6_NA_BUF->tgtipaddr);
lladdr = uip_ds6_nbr_get_ll(nbr);
lladdr = (uip_lladdr_t *)uip_ds6_nbr_get_ll(nbr);
if(nbr == NULL) {
goto discard;
}

View file

@ -25,14 +25,14 @@ void tcpip_input( void )
mac_LowpanToEthernet();
}
uint8_t tcpip_output(uip_lladdr_t * lladdr){
uint8_t tcpip_output(const uip_lladdr_t * lladdr){
if(output != NULL) {
return output(lladdr);
}
return 0;
}
//Called from sicslowpan.c
void tcpip_set_outputfunc(uint8_t (* f)(uip_lladdr_t *)) {
void tcpip_set_outputfunc(uint8_t (* f)(const uip_lladdr_t *)) {
output = f;
}