Skip to content

Commit

Permalink
Merge branch 'net-constify-dev_addr-passing-for-protocols'
Browse files Browse the repository at this point in the history
Jakub Kicinski says:

====================
net: constify dev_addr passing for protocols

Commit 406f42f ("net-next: When a bond have a massive amount
of VLANs...") introduced a rbtree for faster Ethernet address look
up. To maintain netdev->dev_addr in this tree we need to make all
the writes to it got through appropriate helpers.

netdev->dev_addr will be made const to prevent direct writes.
This set sprinkles const across variables and arguments in protocol
code which are used to hold references to netdev->dev_addr.
====================

Link: https://lore.kernel.org/r/20211012155840.4151590-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Oct 13, 2021
2 parents 5f3b8ac + 1bfcd1c commit fe83fe7
Show file tree
Hide file tree
Showing 31 changed files with 63 additions and 58 deletions.
13 changes: 7 additions & 6 deletions include/net/ax25.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ extern spinlock_t ax25_list_lock;
void ax25_cb_add(ax25_cb *);
struct sock *ax25_find_listener(ax25_address *, int, struct net_device *, int);
struct sock *ax25_get_socket(ax25_address *, ax25_address *, int);
ax25_cb *ax25_find_cb(ax25_address *, ax25_address *, ax25_digi *,
ax25_cb *ax25_find_cb(const ax25_address *, ax25_address *, ax25_digi *,
struct net_device *);
void ax25_send_to_raw(ax25_address *, struct sk_buff *, int);
void ax25_destroy_socket(ax25_cb *);
Expand Down Expand Up @@ -384,10 +384,11 @@ struct ax25_linkfail {

void ax25_linkfail_register(struct ax25_linkfail *lf);
void ax25_linkfail_release(struct ax25_linkfail *lf);
int __must_check ax25_listen_register(ax25_address *, struct net_device *);
void ax25_listen_release(ax25_address *, struct net_device *);
int __must_check ax25_listen_register(const ax25_address *,
struct net_device *);
void ax25_listen_release(const ax25_address *, struct net_device *);
int(*ax25_protocol_function(unsigned int))(struct sk_buff *, ax25_cb *);
int ax25_listen_mine(ax25_address *, struct net_device *);
int ax25_listen_mine(const ax25_address *, struct net_device *);
void ax25_link_failed(ax25_cb *, int);
int ax25_protocol_is_registered(unsigned int);

Expand All @@ -401,8 +402,8 @@ netdev_tx_t ax25_ip_xmit(struct sk_buff *skb);
extern const struct header_ops ax25_header_ops;

/* ax25_out.c */
ax25_cb *ax25_send_frame(struct sk_buff *, int, ax25_address *, ax25_address *,
ax25_digi *, struct net_device *);
ax25_cb *ax25_send_frame(struct sk_buff *, int, const ax25_address *,
ax25_address *, ax25_digi *, struct net_device *);
void ax25_output(ax25_cb *, int, struct sk_buff *);
void ax25_kick(ax25_cb *);
void ax25_transmit_buffer(ax25_cb *, struct sk_buff *, int);
Expand Down
2 changes: 1 addition & 1 deletion include/net/datalink.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct datalink_proto {
int (*rcvfunc)(struct sk_buff *, struct net_device *,
struct packet_type *, struct net_device *);
int (*request)(struct datalink_proto *, struct sk_buff *,
unsigned char *);
const unsigned char *);
struct list_head node;
};

Expand Down
2 changes: 1 addition & 1 deletion include/net/dn.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ struct dn_skb_cb {
int iif;
};

static inline __le16 dn_eth2dn(unsigned char *ethaddr)
static inline __le16 dn_eth2dn(const unsigned char *ethaddr)
{
return get_unaligned((__le16 *)(ethaddr + 4));
}
Expand Down
2 changes: 1 addition & 1 deletion include/net/llc.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static inline void llc_sap_put(struct llc_sap *sap)
struct llc_sap *llc_sap_find(unsigned char sap_value);

int llc_build_and_send_ui_pkt(struct llc_sap *sap, struct sk_buff *skb,
unsigned char *dmac, unsigned char dsap);
const unsigned char *dmac, unsigned char dsap);

void llc_sap_handler(struct llc_sap *sap, struct sk_buff *skb);
void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb);
Expand Down
3 changes: 2 additions & 1 deletion include/net/llc_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
#define LLC_STATUS_CONFLICT 7 /* disconnect conn */
#define LLC_STATUS_RESET_DONE 8 /* */

int llc_establish_connection(struct sock *sk, u8 *lmac, u8 *dmac, u8 dsap);
int llc_establish_connection(struct sock *sk, const u8 *lmac, u8 *dmac,
u8 dsap);
int llc_build_and_send_pkt(struct sock *sk, struct sk_buff *skb);
int llc_send_disc(struct sock *sk);
#endif /* LLC_IF_H */
2 changes: 1 addition & 1 deletion include/net/ndisc.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev,
u8 *opt, int opt_len,
struct ndisc_options *ndopts);

void __ndisc_fill_addr_option(struct sk_buff *skb, int type, void *data,
void __ndisc_fill_addr_option(struct sk_buff *skb, int type, const void *data,
int data_len, int pad);

#define NDISC_OPS_REDIRECT_DATA_SPACE 2
Expand Down
8 changes: 4 additions & 4 deletions include/net/rose.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ extern int sysctl_rose_link_fail_timeout;
extern int sysctl_rose_maximum_vcs;
extern int sysctl_rose_window_size;

int rosecmp(rose_address *, rose_address *);
int rosecmpm(rose_address *, rose_address *, unsigned short);
int rosecmp(const rose_address *, const rose_address *);
int rosecmpm(const rose_address *, const rose_address *, unsigned short);
char *rose2asc(char *buf, const rose_address *);
struct sock *rose_find_socket(unsigned int, struct rose_neigh *);
void rose_kill_by_neigh(struct rose_neigh *);
Expand Down Expand Up @@ -205,8 +205,8 @@ extern const struct seq_operations rose_node_seqops;
extern struct seq_operations rose_route_seqops;

void rose_add_loopback_neigh(void);
int __must_check rose_add_loopback_node(rose_address *);
void rose_del_loopback_node(rose_address *);
int __must_check rose_add_loopback_node(const rose_address *);
void rose_del_loopback_node(const rose_address *);
void rose_rt_device_down(struct net_device *);
void rose_link_device_down(struct net_device *);
struct net_device *rose_dev_first(void);
Expand Down
2 changes: 1 addition & 1 deletion net/802/p8022.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <net/p8022.h>

static int p8022_request(struct datalink_proto *dl, struct sk_buff *skb,
unsigned char *dest)
const unsigned char *dest)
{
llc_build_and_send_ui_pkt(dl->sap, skb, dest, dl->sap->laddr.lsap);
return 0;
Expand Down
2 changes: 1 addition & 1 deletion net/802/psnap.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static int snap_rcv(struct sk_buff *skb, struct net_device *dev,
* Put a SNAP header on a frame and pass to 802.2
*/
static int snap_request(struct datalink_proto *dl,
struct sk_buff *skb, u8 *dest)
struct sk_buff *skb, const u8 *dest)
{
memcpy(skb_push(skb, 5), dl->type, 5);
llc_build_and_send_ui_pkt(snap_sap, skb, dest, snap_sap->laddr.lsap);
Expand Down
2 changes: 1 addition & 1 deletion net/ax25/af_ax25.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ struct sock *ax25_get_socket(ax25_address *my_addr, ax25_address *dest_addr,
* Find an AX.25 control block given both ends. It will only pick up
* floating AX.25 control blocks or non Raw socket bound control blocks.
*/
ax25_cb *ax25_find_cb(ax25_address *src_addr, ax25_address *dest_addr,
ax25_cb *ax25_find_cb(const ax25_address *src_addr, ax25_address *dest_addr,
ax25_digi *digi, struct net_device *dev)
{
ax25_cb *s;
Expand Down
2 changes: 1 addition & 1 deletion net/ax25/ax25_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ax25_dev *ax25_addr_ax25dev(ax25_address *addr)

spin_lock_bh(&ax25_dev_lock);
for (ax25_dev = ax25_dev_list; ax25_dev != NULL; ax25_dev = ax25_dev->next)
if (ax25cmp(addr, (ax25_address *)ax25_dev->dev->dev_addr) == 0) {
if (ax25cmp(addr, (const ax25_address *)ax25_dev->dev->dev_addr) == 0) {
res = ax25_dev;
}
spin_unlock_bh(&ax25_dev_lock);
Expand Down
6 changes: 3 additions & 3 deletions net/ax25/ax25_iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void ax25_linkfail_release(struct ax25_linkfail *lf)

EXPORT_SYMBOL(ax25_linkfail_release);

int ax25_listen_register(ax25_address *callsign, struct net_device *dev)
int ax25_listen_register(const ax25_address *callsign, struct net_device *dev)
{
struct listen_struct *listen;

Expand All @@ -121,7 +121,7 @@ int ax25_listen_register(ax25_address *callsign, struct net_device *dev)

EXPORT_SYMBOL(ax25_listen_register);

void ax25_listen_release(ax25_address *callsign, struct net_device *dev)
void ax25_listen_release(const ax25_address *callsign, struct net_device *dev)
{
struct listen_struct *s, *listen;

Expand Down Expand Up @@ -171,7 +171,7 @@ int (*ax25_protocol_function(unsigned int pid))(struct sk_buff *, ax25_cb *)
return res;
}

int ax25_listen_mine(ax25_address *callsign, struct net_device *dev)
int ax25_listen_mine(const ax25_address *callsign, struct net_device *dev)
{
struct listen_struct *listen;

Expand Down
4 changes: 2 additions & 2 deletions net/ax25/ax25_in.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ static int ax25_process_rx_frame(ax25_cb *ax25, struct sk_buff *skb, int type, i
}

static int ax25_rcv(struct sk_buff *skb, struct net_device *dev,
ax25_address *dev_addr, struct packet_type *ptype)
const ax25_address *dev_addr, struct packet_type *ptype)
{
ax25_address src, dest, *next_digi = NULL;
int type = 0, mine = 0, dama;
Expand Down Expand Up @@ -447,5 +447,5 @@ int ax25_kiss_rcv(struct sk_buff *skb, struct net_device *dev,

skb_pull(skb, AX25_KISS_HEADER_LEN); /* Remove the KISS byte */

return ax25_rcv(skb, dev, (ax25_address *)dev->dev_addr, ptype);
return ax25_rcv(skb, dev, (const ax25_address *)dev->dev_addr, ptype);
}
2 changes: 1 addition & 1 deletion net/ax25/ax25_out.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

static DEFINE_SPINLOCK(ax25_frag_lock);

ax25_cb *ax25_send_frame(struct sk_buff *skb, int paclen, ax25_address *src, ax25_address *dest, ax25_digi *digi, struct net_device *dev)
ax25_cb *ax25_send_frame(struct sk_buff *skb, int paclen, const ax25_address *src, ax25_address *dest, ax25_digi *digi, struct net_device *dev)
{
ax25_dev *ax25_dev;
ax25_cb *ax25;
Expand Down
4 changes: 2 additions & 2 deletions net/ipv6/addrconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2237,12 +2237,12 @@ static int addrconf_ifid_6lowpan(u8 *eui, struct net_device *dev)

static int addrconf_ifid_ieee1394(u8 *eui, struct net_device *dev)
{
union fwnet_hwaddr *ha;
const union fwnet_hwaddr *ha;

if (dev->addr_len != FWNET_ALEN)
return -1;

ha = (union fwnet_hwaddr *)dev->dev_addr;
ha = (const union fwnet_hwaddr *)dev->dev_addr;

memcpy(eui, &ha->uc.uniq_id, sizeof(ha->uc.uniq_id));
eui[0] ^= 2;
Expand Down
4 changes: 2 additions & 2 deletions net/ipv6/ndisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ struct neigh_table nd_tbl = {
};
EXPORT_SYMBOL_GPL(nd_tbl);

void __ndisc_fill_addr_option(struct sk_buff *skb, int type, void *data,
void __ndisc_fill_addr_option(struct sk_buff *skb, int type, const void *data,
int data_len, int pad)
{
int space = __ndisc_opt_addr_space(data_len, pad);
Expand All @@ -165,7 +165,7 @@ void __ndisc_fill_addr_option(struct sk_buff *skb, int type, void *data,
EXPORT_SYMBOL_GPL(__ndisc_fill_addr_option);

static inline void ndisc_fill_addr_option(struct sk_buff *skb, int type,
void *data, u8 icmp6_type)
const void *data, u8 icmp6_type)
{
__ndisc_fill_addr_option(skb, type, data, skb->dev->addr_len,
ndisc_addr_option_pad(skb->dev->type));
Expand Down
2 changes: 1 addition & 1 deletion net/llc/llc_c_ac.c
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ int llc_conn_ac_send_sabme_cmd_p_set_x(struct sock *sk, struct sk_buff *skb)

if (nskb) {
struct llc_sap *sap = llc->sap;
u8 *dmac = llc->daddr.mac;
const u8 *dmac = llc->daddr.mac;

if (llc->dev->flags & IFF_LOOPBACK)
dmac = llc->dev->dev_addr;
Expand Down
2 changes: 1 addition & 1 deletion net/llc/llc_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ int llc_build_and_send_pkt(struct sock *sk, struct sk_buff *skb)
* establishment will inform to upper layer via calling it's confirm
* function and passing proper information.
*/
int llc_establish_connection(struct sock *sk, u8 *lmac, u8 *dmac, u8 dsap)
int llc_establish_connection(struct sock *sk, const u8 *lmac, u8 *dmac, u8 dsap)
{
int rc = -EISCONN;
struct llc_addr laddr, daddr;
Expand Down
2 changes: 1 addition & 1 deletion net/llc/llc_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int llc_mac_hdr_init(struct sk_buff *skb,
* package primitive as an event and send to SAP event handler
*/
int llc_build_and_send_ui_pkt(struct llc_sap *sap, struct sk_buff *skb,
unsigned char *dmac, unsigned char dsap)
const unsigned char *dmac, unsigned char dsap)
{
int rc;
llc_pdu_header_init(skb, LLC_PDU_TYPE_U, sap->laddr.lsap,
Expand Down
2 changes: 1 addition & 1 deletion net/llc/llc_proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <net/llc_c_st.h>
#include <net/llc_conn.h>

static void llc_ui_format_mac(struct seq_file *seq, u8 *addr)
static void llc_ui_format_mac(struct seq_file *seq, const u8 *addr)
{
seq_printf(seq, "%pM", addr);
}
Expand Down
4 changes: 2 additions & 2 deletions net/netrom/af_netrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ static int nr_connect(struct socket *sock, struct sockaddr *uaddr,
struct sock *sk = sock->sk;
struct nr_sock *nr = nr_sk(sk);
struct sockaddr_ax25 *addr = (struct sockaddr_ax25 *)uaddr;
ax25_address *source = NULL;
const ax25_address *source = NULL;
ax25_uid_assoc *user;
struct net_device *dev;
int err = 0;
Expand Down Expand Up @@ -673,7 +673,7 @@ static int nr_connect(struct socket *sock, struct sockaddr *uaddr,
err = -ENETUNREACH;
goto out_release;
}
source = (ax25_address *)dev->dev_addr;
source = (const ax25_address *)dev->dev_addr;

user = ax25_findbyuid(current_euid());
if (user) {
Expand Down
6 changes: 3 additions & 3 deletions net/netrom/nr_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static int __must_check nr_set_mac_address(struct net_device *dev, void *addr)
if (err)
return err;

ax25_listen_release((ax25_address *)dev->dev_addr, NULL);
ax25_listen_release((const ax25_address *)dev->dev_addr, NULL);
}

dev_addr_set(dev, sa->sa_data);
Expand All @@ -120,7 +120,7 @@ static int nr_open(struct net_device *dev)
{
int err;

err = ax25_listen_register((ax25_address *)dev->dev_addr, NULL);
err = ax25_listen_register((const ax25_address *)dev->dev_addr, NULL);
if (err)
return err;

Expand All @@ -131,7 +131,7 @@ static int nr_open(struct net_device *dev)

static int nr_close(struct net_device *dev)
{
ax25_listen_release((ax25_address *)dev->dev_addr, NULL);
ax25_listen_release((const ax25_address *)dev->dev_addr, NULL);
netif_stop_queue(dev);
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions net/netrom/nr_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ struct net_device *nr_dev_get(ax25_address *addr)
rcu_read_lock();
for_each_netdev_rcu(&init_net, dev) {
if ((dev->flags & IFF_UP) && dev->type == ARPHRD_NETROM &&
ax25cmp(addr, (ax25_address *)dev->dev_addr) == 0) {
ax25cmp(addr, (const ax25_address *)dev->dev_addr) == 0) {
dev_hold(dev);
goto out;
}
Expand Down Expand Up @@ -825,7 +825,7 @@ int nr_route_frame(struct sk_buff *skb, ax25_cb *ax25)

ax25s = nr_neigh->ax25;
nr_neigh->ax25 = ax25_send_frame(skb, 256,
(ax25_address *)dev->dev_addr,
(const ax25_address *)dev->dev_addr,
&nr_neigh->callsign,
nr_neigh->digipeat, nr_neigh->dev);
if (ax25s)
Expand Down
5 changes: 3 additions & 2 deletions net/rose/af_rose.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ char *rose2asc(char *buf, const rose_address *addr)
/*
* Compare two ROSE addresses, 0 == equal.
*/
int rosecmp(rose_address *addr1, rose_address *addr2)
int rosecmp(const rose_address *addr1, const rose_address *addr2)
{
int i;

Expand All @@ -123,7 +123,8 @@ int rosecmp(rose_address *addr1, rose_address *addr2)
/*
* Compare two ROSE addresses for only mask digits, 0 == equal.
*/
int rosecmpm(rose_address *addr1, rose_address *addr2, unsigned short mask)
int rosecmpm(const rose_address *addr1, const rose_address *addr2,
unsigned short mask)
{
unsigned int i, j;

Expand Down
6 changes: 3 additions & 3 deletions net/rose/rose_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static int rose_set_mac_address(struct net_device *dev, void *addr)
if (err)
return err;

rose_del_loopback_node((rose_address *)dev->dev_addr);
rose_del_loopback_node((const rose_address *)dev->dev_addr);
}

dev_addr_set(dev, sa->sa_data);
Expand All @@ -78,7 +78,7 @@ static int rose_open(struct net_device *dev)
{
int err;

err = rose_add_loopback_node((rose_address *)dev->dev_addr);
err = rose_add_loopback_node((const rose_address *)dev->dev_addr);
if (err)
return err;

Expand All @@ -90,7 +90,7 @@ static int rose_open(struct net_device *dev)
static int rose_close(struct net_device *dev)
{
netif_stop_queue(dev);
rose_del_loopback_node((rose_address *)dev->dev_addr);
rose_del_loopback_node((const rose_address *)dev->dev_addr);
return 0;
}

Expand Down
8 changes: 4 additions & 4 deletions net/rose/rose_link.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ static void rose_t0timer_expiry(struct timer_list *t)
*/
static int rose_send_frame(struct sk_buff *skb, struct rose_neigh *neigh)
{
ax25_address *rose_call;
const ax25_address *rose_call;
ax25_cb *ax25s;

if (ax25cmp(&rose_callsign, &null_ax25_address) == 0)
rose_call = (ax25_address *)neigh->dev->dev_addr;
rose_call = (const ax25_address *)neigh->dev->dev_addr;
else
rose_call = &rose_callsign;

Expand All @@ -117,11 +117,11 @@ static int rose_send_frame(struct sk_buff *skb, struct rose_neigh *neigh)
*/
static int rose_link_up(struct rose_neigh *neigh)
{
ax25_address *rose_call;
const ax25_address *rose_call;
ax25_cb *ax25s;

if (ax25cmp(&rose_callsign, &null_ax25_address) == 0)
rose_call = (ax25_address *)neigh->dev->dev_addr;
rose_call = (const ax25_address *)neigh->dev->dev_addr;
else
rose_call = &rose_callsign;

Expand Down
Loading

0 comments on commit fe83fe7

Please sign in to comment.