Commit 857e8a67 authored by David S. Miller's avatar David S. Miller

Merge branch 'batman-hdlc'

Andrew Lunn says:

====================
Allow BATMAN to use hdlc-eth interfaces

BATMAN works over Ethernet like interfaces. hdlc-eth provides the need
requirements. However, hdlc devices are often created as raw hdlc
devices, which batman cannot use, and are then be transmuted into
other types using sethdlc(1). Have the HDLC code emit
NETDEV_*_TYPE_CHANGE events when the type changes, and have BATMAN
react on these events.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 2141eaf0 a1a66b11
...@@ -266,8 +266,8 @@ struct net_device *alloc_hdlcdev(void *priv) ...@@ -266,8 +266,8 @@ struct net_device *alloc_hdlcdev(void *priv)
void unregister_hdlc_device(struct net_device *dev) void unregister_hdlc_device(struct net_device *dev)
{ {
rtnl_lock(); rtnl_lock();
unregister_netdevice(dev);
detach_hdlc_protocol(dev); detach_hdlc_protocol(dev);
unregister_netdevice(dev);
rtnl_unlock(); rtnl_unlock();
} }
...@@ -276,7 +276,11 @@ void unregister_hdlc_device(struct net_device *dev) ...@@ -276,7 +276,11 @@ void unregister_hdlc_device(struct net_device *dev)
int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto, int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto,
size_t size) size_t size)
{ {
detach_hdlc_protocol(dev); int err;
err = detach_hdlc_protocol(dev);
if (err)
return err;
if (!try_module_get(proto->module)) if (!try_module_get(proto->module))
return -ENOSYS; return -ENOSYS;
...@@ -289,15 +293,24 @@ int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto, ...@@ -289,15 +293,24 @@ int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto,
} }
} }
dev_to_hdlc(dev)->proto = proto; dev_to_hdlc(dev)->proto = proto;
return 0; return 0;
} }
void detach_hdlc_protocol(struct net_device *dev) int detach_hdlc_protocol(struct net_device *dev)
{ {
hdlc_device *hdlc = dev_to_hdlc(dev); hdlc_device *hdlc = dev_to_hdlc(dev);
int err;
if (hdlc->proto) { if (hdlc->proto) {
err = call_netdevice_notifiers(NETDEV_PRE_TYPE_CHANGE, dev);
err = notifier_to_errno(err);
if (err) {
netdev_err(dev, "Refused to change device type\n");
return err;
}
if (hdlc->proto->detach) if (hdlc->proto->detach)
hdlc->proto->detach(dev); hdlc->proto->detach(dev);
module_put(hdlc->proto->module); module_put(hdlc->proto->module);
...@@ -306,6 +319,8 @@ void detach_hdlc_protocol(struct net_device *dev) ...@@ -306,6 +319,8 @@ void detach_hdlc_protocol(struct net_device *dev)
kfree(hdlc->state); kfree(hdlc->state);
hdlc->state = NULL; hdlc->state = NULL;
hdlc_setup_dev(dev); hdlc_setup_dev(dev);
return 0;
} }
......
...@@ -378,6 +378,7 @@ static int cisco_ioctl(struct net_device *dev, struct ifreq *ifr) ...@@ -378,6 +378,7 @@ static int cisco_ioctl(struct net_device *dev, struct ifreq *ifr)
spin_lock_init(&state(hdlc)->lock); spin_lock_init(&state(hdlc)->lock);
dev->header_ops = &cisco_header_ops; dev->header_ops = &cisco_header_ops;
dev->type = ARPHRD_CISCO; dev->type = ARPHRD_CISCO;
call_netdevice_notifiers(NETDEV_POST_TYPE_CHANGE, dev);
netif_dormant_on(dev); netif_dormant_on(dev);
return 0; return 0;
} }
......
...@@ -1240,6 +1240,7 @@ static int fr_ioctl(struct net_device *dev, struct ifreq *ifr) ...@@ -1240,6 +1240,7 @@ static int fr_ioctl(struct net_device *dev, struct ifreq *ifr)
} }
memcpy(&state(hdlc)->settings, &new_settings, size); memcpy(&state(hdlc)->settings, &new_settings, size);
dev->type = ARPHRD_FRAD; dev->type = ARPHRD_FRAD;
call_netdevice_notifiers(NETDEV_POST_TYPE_CHANGE, dev);
return 0; return 0;
case IF_PROTO_FR_ADD_PVC: case IF_PROTO_FR_ADD_PVC:
......
...@@ -687,6 +687,7 @@ static int ppp_ioctl(struct net_device *dev, struct ifreq *ifr) ...@@ -687,6 +687,7 @@ static int ppp_ioctl(struct net_device *dev, struct ifreq *ifr)
dev->hard_header_len = sizeof(struct hdlc_header); dev->hard_header_len = sizeof(struct hdlc_header);
dev->header_ops = &ppp_header_ops; dev->header_ops = &ppp_header_ops;
dev->type = ARPHRD_PPP; dev->type = ARPHRD_PPP;
call_netdevice_notifiers(NETDEV_POST_TYPE_CHANGE, dev);
netif_dormant_on(dev); netif_dormant_on(dev);
return 0; return 0;
} }
......
...@@ -84,6 +84,7 @@ static int raw_ioctl(struct net_device *dev, struct ifreq *ifr) ...@@ -84,6 +84,7 @@ static int raw_ioctl(struct net_device *dev, struct ifreq *ifr)
return result; return result;
memcpy(hdlc->state, &new_settings, size); memcpy(hdlc->state, &new_settings, size);
dev->type = ARPHRD_RAWHDLC; dev->type = ARPHRD_RAWHDLC;
call_netdevice_notifiers(NETDEV_POST_TYPE_CHANGE, dev);
netif_dormant_off(dev); netif_dormant_off(dev);
return 0; return 0;
} }
......
...@@ -102,6 +102,7 @@ static int raw_eth_ioctl(struct net_device *dev, struct ifreq *ifr) ...@@ -102,6 +102,7 @@ static int raw_eth_ioctl(struct net_device *dev, struct ifreq *ifr)
ether_setup(dev); ether_setup(dev);
dev->tx_queue_len = old_qlen; dev->tx_queue_len = old_qlen;
eth_hw_addr_random(dev); eth_hw_addr_random(dev);
call_netdevice_notifiers(NETDEV_POST_TYPE_CHANGE, dev);
netif_dormant_off(dev); netif_dormant_off(dev);
return 0; return 0;
} }
......
...@@ -213,6 +213,7 @@ static int x25_ioctl(struct net_device *dev, struct ifreq *ifr) ...@@ -213,6 +213,7 @@ static int x25_ioctl(struct net_device *dev, struct ifreq *ifr)
if ((result = attach_hdlc_protocol(dev, &proto, 0))) if ((result = attach_hdlc_protocol(dev, &proto, 0)))
return result; return result;
dev->type = ARPHRD_X25; dev->type = ARPHRD_X25;
call_netdevice_notifiers(NETDEV_POST_TYPE_CHANGE, dev);
netif_dormant_off(dev); netif_dormant_off(dev);
return 0; return 0;
} }
......
...@@ -101,7 +101,7 @@ netdev_tx_t hdlc_start_xmit(struct sk_buff *skb, struct net_device *dev); ...@@ -101,7 +101,7 @@ netdev_tx_t hdlc_start_xmit(struct sk_buff *skb, struct net_device *dev);
int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto, int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto,
size_t size); size_t size);
/* May be used by hardware driver to gain control over HDLC device */ /* May be used by hardware driver to gain control over HDLC device */
void detach_hdlc_protocol(struct net_device *dev); int detach_hdlc_protocol(struct net_device *dev);
static __inline__ __be16 hdlc_type_trans(struct sk_buff *skb, static __inline__ __be16 hdlc_type_trans(struct sk_buff *skb,
struct net_device *dev) struct net_device *dev)
......
...@@ -709,7 +709,8 @@ static int batadv_hard_if_event(struct notifier_block *this, ...@@ -709,7 +709,8 @@ static int batadv_hard_if_event(struct notifier_block *this,
} }
hard_iface = batadv_hardif_get_by_netdev(net_dev); hard_iface = batadv_hardif_get_by_netdev(net_dev);
if (!hard_iface && event == NETDEV_REGISTER) if (!hard_iface && (event == NETDEV_REGISTER ||
event == NETDEV_POST_TYPE_CHANGE))
hard_iface = batadv_hardif_add_interface(net_dev); hard_iface = batadv_hardif_add_interface(net_dev);
if (!hard_iface) if (!hard_iface)
...@@ -724,6 +725,7 @@ static int batadv_hard_if_event(struct notifier_block *this, ...@@ -724,6 +725,7 @@ static int batadv_hard_if_event(struct notifier_block *this,
batadv_hardif_deactivate_interface(hard_iface); batadv_hardif_deactivate_interface(hard_iface);
break; break;
case NETDEV_UNREGISTER: case NETDEV_UNREGISTER:
case NETDEV_PRE_TYPE_CHANGE:
list_del_rcu(&hard_iface->list); list_del_rcu(&hard_iface->list);
batadv_hardif_remove_interface(hard_iface); batadv_hardif_remove_interface(hard_iface);
......
...@@ -3287,6 +3287,7 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event, ...@@ -3287,6 +3287,7 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event,
case NETDEV_PRE_TYPE_CHANGE: case NETDEV_PRE_TYPE_CHANGE:
case NETDEV_POST_TYPE_CHANGE: case NETDEV_POST_TYPE_CHANGE:
if (idev)
addrconf_type_change(dev, event); addrconf_type_change(dev, event);
break; break;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment