net/x25: add/remove x25_link_device by NETDEV_REGISTER/UNREGISTER
Subsystems (3)
Martin Schiller
maintainerPATCH 1/6 net/x25: add/remove x25_link_device by NETDEV_REGISTER/UNREGISTER
and also by NETDEV_POST_TYPE_CHANGE/NETDEV_PRE_TYPE_CHANGE.
This change is needed so that the x25_neigh struct for an interface is already created when it shows up and is kept independantly if the interface goes UP or DOWN.
This is used in the next commit, where x25 params of an neighbour will get configurable through ioctls.
--- include/net/x25.h | 2 ++ net/x25/af_x25.c | 19 +++++++++++++++++ net/x25/x25_link.c | 51 ++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 66 insertions(+), 6 deletions(-)
include/net/x25.h +2 -0
@@ -231,6 +231,8 @@ int x25_backlog_rcv(struct sock *, struct sk_buff *);/* x25_link.c */ void x25_link_control (struct sk_buff *,struct x25_neigh *,unsigned short ); +void x25_link_device_add (struct net_device *); +void x25_link_device_remove (struct net_device *);void x25_link_device_up (struct net_device *);void x25_link_device_down (struct net_device *);void x25_link_established (struct x25_neigh *);
net/x25/af_x25.c +19 -0
@@ -233,10 +233,20 @@ static int x25_device_event(struct notifier_block *this, unsigned long event,#endif ) {switch (event) { +case NETDEV_REGISTER : +pr_debug ("X.25: got event NETDEV_REGISTER for device: %s\n" , dev->name); +x25_link_device_add (dev); +break ; +case NETDEV_POST_TYPE_CHANGE : +pr_debug ("X.25: got event NETDEV_POST_TYPE_CHANGE for device: %s\n" , dev->name); +x25_link_device_add (dev); +break ;case NETDEV_UP : +pr_debug ("X.25: got event NETDEV_UP for device: %s\n" , dev->name);x25_link_device_up (dev);break ;case NETDEV_GOING_DOWN : +pr_debug ("X.25: got event NETDEV_GOING_DOWN for device: %s\n" , dev->name); nb =x25_get_neigh (dev);if (nb) {x25_terminate_link (nb);
@@ -244,10 +254,19 @@ static int x25_device_event(struct notifier_block *this, unsigned long event, }break ;case NETDEV_DOWN : +pr_debug ("X.25: got event NETDEV_DOWN for device: %s\n" , dev->name);x25_kill_by_device (dev);x25_route_device_down (dev);x25_link_device_down (dev);break ; +case NETDEV_PRE_TYPE_CHANGE : +pr_debug ("X.25: got event NETDEV_PRE_TYPE_CHANGE for device: %s\n" , dev->name); +x25_link_device_remove (dev); +break ; +case NETDEV_UNREGISTER : +pr_debug ("X.25: got event NETDEV_UNREGISTER for device: %s\n" , dev->name); +x25_link_device_remove (dev); +break ; } }
net/x25/x25_link.c +45 -6
82 lines not on this page · raw message
Signature · 1 line
2.20.1
Martin Schiller
maintainerPATCH 2/6 net/x25: make neighbour params configurable
Extended struct x25_neigh and x25_subscrip_struct to configure following params through SIOCX25SSUBSCRIP:
o mode (DTE/DCE)
o number of channels
o facilities (packet size, window size)
o timer T20
Based on this configuration options the follwing changes/extensions where made:
o DTE/DCE handling to select the next lc (DCE=from bottom / DTE=from top)
o DTE/DCE handling to set correct clear/reset/restart cause
o take default facilities from neighbour settings
--- include/net/x25.h | 7 ++- include/uapi/linux/x25.h | 54 ++++++++-------- net/x25/af_x25.c | 132 ++++++++++++++++++++++++++++++++------- net/x25/x25_facilities.c | 6 +- net/x25/x25_link.c | 104 +++++++++++++++++++++++++----- net/x25/x25_subr.c | 22 ++++++- 6 files changed, 255 insertions(+), 70 deletions(-)
include/net/x25.h +6 -1
@@ -140,6 +140,9 @@ struct x25_neigh {struct net_device *dev;unsigned int state;unsigned int extended; +unsigned int dce; +unsigned int lc; +struct x25_facilities facilities;struct sk_buff_head queue;unsigned long t20;struct timer_list t20timer;
@@ -164,6 +167,7 @@ struct x25_sock {struct timer_list timer;struct x25_causediag causediag;struct x25_facilities facilities; +unsigned int socket_defined_facilities;/* set, if facilities changed by SIOCX25SFACILITIES */ struct x25_dte_facilities dte_facilities;struct x25_calluserdata calluserdata;unsigned long vc_facil_mask;/* inc_call facilities mask */
@@ -215,7 +219,8 @@ int x25_create_facilities(unsigned char *, struct x25_facilities *, struct x25_dte_facilities *, unsigned long);int x25_negotiate_facilities (struct sk_buff *,struct sock *,struct x25_facilities *, -struct x25_dte_facilities *); +struct x25_dte_facilities *, +struct x25_neigh *);void x25_limit_facilities (struct x25_facilities *,struct x25_neigh *);/* x25_forward.c */
include/uapi/linux/x25.h +29 -25
66 lines not on this page · raw message
net/x25/af_x25.c +108 -24
221 lines not on this page · raw message
net/x25/x25_facilities.c +5 -1
@@ -263,13 +263,17 @@ int x25_create_facilities(unsigned char *buffer,* The only real problem is with reverse charging. */ int x25_negotiate_facilities (struct sk_buff *skb,struct sock *sk, -struct x25_facilities *new,struct x25_dte_facilities *dte) +struct x25_facilities *new,struct x25_dte_facilities *dte, +struct x25_neigh *nb) {struct x25_sock *x25 =x25_sk (sk);struct x25_facilities *ours = &x25->facilities;struct x25_facilities theirs;int len; +if (!x25->socket_defined_facilities) + ours = &nb->facilities; +memset (&theirs,0 ,sizeof (theirs));memcpy (new, ours,sizeof (*new));memset (dte,0 ,sizeof (*dte));
net/x25/x25_link.c +88 -16
148 lines not on this page · raw message
net/x25/x25_subr.c +19 -3
@@ -218,15 +218,31 @@ void x25_write_internal(struct sock *sk, int frametype)case X25_CLEAR_REQUEST : dptr =skb_put (skb,3 ); *dptr++ = frametype; - *dptr++ = x25->causediag.cause; + + *dptr = x25->causediag.cause; + +/* set bit 8, if DTE and cause != 0x00 */ +if (!x25->neighbour->dce && *dptr !=0x00 ) + *dptr |= (unsigned char )0x80 ; + + dptr++; + *dptr++ = x25->causediag.diagnostic;break ;case X25_RESET_REQUEST : dptr =skb_put (skb,3 ); *dptr++ = frametype; - *dptr++ =0x00 ;/* XXX */ - *dptr++ =0x00 ;/* XXX */ + + *dptr =0x00 ;/* cause */ + +/* set bit 8, if DTE and cause != 0x00 */ +if (!x25->neighbour->dce && *dptr !=0x00 ) + *dptr |= (unsigned char )0x80 ; + + dptr++; + + *dptr++ =0x00 ;/* diagnostic */ break ;case X25_RR :
Signature · 1 line
2.20.1
kernel test robot
build botRe: [PATCH 2/6] net/x25: make neighbour params configurable
Thank you for the patch! Yet something to improve:
Hi Martin,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on net-next/master]
[also build test ERROR on net/master linus/master sparc-next/master v5.10-rc4 next-20201116] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Martin-Schiller/net-x25-add-remove-x25_link_device-by-NETDEV_REGISTER-UNREGISTER/20201116-153459 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 0064c5c1b3bf2a695c772c90e8dea38426a870ff config: x86_64-randconfig-a011-20201116 (attached as .config) compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project c044709b8fbea2a9a375e4173a6bd735f6866c0c)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# https://github.com/0day-ci/linux/commit/2d44533245f7e8388db93c53c26703ac52650e57
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Martin-Schiller/net-x25-add-remove-x25_link_device-by-NETDEV_REGISTER-UNREGISTER/20201116-153459 git checkout 2d44533245f7e8388db93c53c26703ac52650e57
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> net/x25/af_x25.c:1709:30: error: assigning to 'struct compat_x25_facilities' from incompatible type 'struct x25_facilities'
x25_subscr.facilities = nb->facilities;
^ ~~~~~~~~~~~~~~
>> net/x25/af_x25.c:1761:24: error: assigning to 'struct x25_facilities' from incompatible type 'struct compat_x25_facilities'
nb->facilities = x25_subscr.facilities;
^ ~~~~~~~~~~~~~~~~~~~~~2 errors generated.
vim +1709 net/x25/af_x25.c
1678
1679 #ifdef CONFIG_COMPAT
1680 static int compat_x25_subscr_ioctl(unsigned int cmd,
1681 struct compat_x25_subscrip_struct __user *x25_subscr32)
1682 {
1683 struct compat_x25_subscrip_struct x25_subscr;
1684 struct x25_neigh *nb;
1685 struct net_device *dev;
1686 int rc = -EINVAL;
1687
1688 if (cmd != SIOCX25GSUBSCRIP && cmd != SIOCX25SSUBSCRIP)
1689 goto out;
1690
1691 rc = -EFAULT;
1692 if (copy_from_user(&x25_subscr, x25_subscr32, sizeof(*x25_subscr32)))
1693 goto out;
1694
1695 rc = -EINVAL;
1696 dev = x25_dev_get(x25_subscr.device);
1697 if (dev == NULL)
1698 goto out;
1699
1700 nb = x25_get_neigh(dev);
1701 if (nb == NULL)
1702 goto out_dev_put;
1703
1704 if (cmd == SIOCX25GSUBSCRIP) {
1705 read_lock_bh(&x25_neigh_list_lock);
1706 x25_subscr.extended = nb->extended;
1707 x25_subscr.dce = nb->dce;
1708 x25_subscr.lc = nb->lc;
> 1709 x25_subscr.facilities = nb->facilities;
1710 x25_subscr.t20 = nb->t20;
1711 x25_subscr.global_facil_mask = nb->global_facil_mask;
1712 read_unlock_bh(&x25_neigh_list_lock);
1713 rc = copy_to_user(x25_subscr32, &x25_subscr,
1714 sizeof(*x25_subscr32)) ? -EFAULT : 0;
1715 } else {
1716 rc = -EINVAL;
1717
1718 if (dev->flags & IFF_UP)
1719 return -EBUSY;
1720
1721 if (x25_subscr.extended != 0 && x25_subscr.extended != 1)
1722 goto out_dev_and_neigh_put;
1723 if (x25_subscr.dce != 0 && x25_subscr.dce != 1)
1724 goto out_dev_and_neigh_put;
1725 if (x25_subscr.lc < 1 || x25_subscr.lc > 4095)
1726 goto out_dev_and_neigh_put;
1727 if (x25_subscr.facilities.pacsize_in < X25_PS16 ||
1728 x25_subscr.facilities.pacsize_in > X25_PS4096)
1729 goto out_dev_and_neigh_put;
1730 if (x25_subscr.facilities.pacsize_out < X25_PS16 ||
1731 x25_subscr.facilities.pacsize_out > X25_PS4096)
1732 goto out_dev_and_neigh_put;
1733 if (x25_subscr.facilities.winsize_in < 1 ||
1734 x25_subscr.facilities.winsize_in > 127)
1735 goto out_dev_and_neigh_put;
1736 if (x25_subscr.facilities.throughput) {
1737 int out = x25_subscr.facilities.throughput & 0xf0;
1738 int in = x25_subscr.facilities.throughput & 0x0f;
1739 if (!out)
1740 x25_subscr.facilities.throughput |=
1741 X25_DEFAULT_THROUGHPUT << 4;
1742 else if (out < 0x30 || out > 0xD0)
1743 goto out_dev_and_neigh_put;
1744 if (!in)
1745 x25_subscr.facilities.throughput |=
1746 X25_DEFAULT_THROUGHPUT;
1747 else if (in < 0x03 || in > 0x0D)
1748 goto out_dev_and_neigh_put;
1749 }
1750 if (x25_subscr.facilities.reverse &&
1751 (x25_subscr.facilities.reverse & 0x81) != 0x81)
1752 goto out_dev_and_neigh_put;
1753 if (x25_subscr.t20 < 1 * HZ || x25_subscr.t20 > 300 * HZ)
1754 goto out_dev_and_neigh_put;
1755
1756 rc = 0;
1757 write_lock_bh(&x25_neigh_list_lock);
1758 nb->extended = x25_subscr.extended;
1759 nb->dce = x25_subscr.dce;
1760 nb->lc = x25_subscr.lc;
> 1761 nb->facilities = x25_subscr.facilities; 1762 nb->t20 = x25_subscr.t20;
1763 nb->global_facil_mask = x25_subscr.global_facil_mask;
1764 write_unlock_bh(&x25_neigh_list_lock);
1765 }
1766 dev_put(dev);
1767
1768 x25_neigh_put(nb);
1769 out:
1770 return rc;
1771 out_dev_and_neigh_put:
1772 x25_neigh_put(nb);
1773 out_dev_put:
1774 dev_put(dev);
1775 goto out;
1776 }
1777
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
Martin Schiller
maintainerPATCH 3/6 net/x25: replace x25_kill_by_device with x25_kill_by_neigh
In reply to Martin SchillerRemove unnecessary function x25_kill_by_device.
--- net/x25/af_x25.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-)
net/x25/af_x25.c +5 -17
@@ -210,22 +210,6 @@ static void x25_remove_socket(struct sock *sk)write_unlock_bh (&x25_list_lock); } -/* -* Kill all bound sockets on a dropped device. -*/ -static void x25_kill_by_device (struct net_device *dev) -{ -struct sock *s; - -write_lock_bh (&x25_list_lock); - -sk_for_each (s, &x25_list) -if (x25_sk (s)->neighbour &&x25_sk (s)->neighbour->dev == dev) -x25_disconnect (s,ENETUNREACH ,0 ,0 ); - -write_unlock_bh (&x25_list_lock); -} -/* * Handle device status changes. */
@@ -266,7 +250,11 @@ static int x25_device_event(struct notifier_block *this, unsigned long event,break ;case NETDEV_DOWN :pr_debug ("X.25: got event NETDEV_DOWN for device: %s\n" , dev->name); -x25_kill_by_device (dev); + nb =x25_get_neigh (dev); +if (nb) { +x25_kill_by_neigh (nb); +x25_neigh_put (nb); + }x25_route_device_down (dev);x25_link_device_down (dev);break ;
Signature · 1 line
2.20.1
Martin Schiller
maintainerPATCH 4/6 net/x25: support NETDEV_CHANGE notifier
In reply to Martin SchillerThis makes it possible to handle carrier lost and detection. In case of carrier lost, we shutdown layer 3 and flush all sessions.
--- net/x25/af_x25.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
net/x25/af_x25.c +11 -0
@@ -266,6 +266,17 @@ static int x25_device_event(struct notifier_block *this, unsigned long event,pr_debug ("X.25: got event NETDEV_UNREGISTER for device: %s\n" , dev->name);x25_link_device_remove (dev);break ; +case NETDEV_CHANGE : +pr_debug ("X.25: got event NETDEV_CHANGE for device: %s\n" , dev->name); +if (!netif_carrier_ok (dev)) { +pr_debug ("X.25: Carrier lost -> set link state down: %s\n" , dev->name); + nb =x25_get_neigh (dev); +if (nb) { +x25_link_terminated (nb); +x25_neigh_put (nb); + } + } +break ; } }
Signature · 1 line
2.20.1
Martin Schiller
maintainerPATCH 5/6 net/lapb: support netdev events
In reply to Martin SchillerThis makes it possible to handle carrier loss and detection. In case of Carrier Loss, layer 2 is terminated
In case of Carrier Detection, we start timer t1 on a DCE interface, and on a DTE interface we change to state LAPB_STATE_1 and start sending SABM(E).
--- net/lapb/lapb_iface.c | 74 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+)
net/lapb/lapb_iface.c +74 -0
@@ -418,14 +418,88 @@ int lapb_data_transmit(struct lapb_cb *lapb, struct sk_buff *skb)return used; } +/* +* Handle device status changes. +*/ +static int lapb_device_event (struct notifier_block *this,unsigned long event, +void *ptr) +{ +struct net_device *dev = ptr; +struct lapb_cb *lapb; + +if (!net_eq (dev_net (dev), &init_net)) +return NOTIFY_DONE ; + +if (dev->type ==ARPHRD_X25 ) { +switch (event) { +case NETDEV_REGISTER : +lapb_dbg (0 ,"(%p): got event NETDEV_REGISTER for device: %s\n" , dev, dev->name); +break ; +case NETDEV_POST_TYPE_CHANGE : +lapb_dbg (0 ,"(%p): got event NETDEV_POST_TYPE_CHANGE for device: %s\n" , dev, dev->name); +break ; +case NETDEV_UP : +lapb_dbg (0 ,"(%p): got event NETDEV_UP for device: %s\n" , dev, dev->name); +break ; +case NETDEV_GOING_DOWN : +lapb_dbg (0 ,"(%p): got event NETDEV_GOING_DOWN for device: %s\n" , dev, dev->name); +break ; +case NETDEV_DOWN : +lapb_dbg (0 ,"(%p): got event NETDEV_DOWN for device: %s\n" , dev, dev->name); +break ; +case NETDEV_PRE_TYPE_CHANGE : +lapb_dbg (0 ,"(%p): got event NETDEV_PRE_TYPE_CHANGE for device: %s\n" , dev, dev->name); +break ; +case NETDEV_UNREGISTER : +lapb_dbg (0 ,"(%p): got event NETDEV_UNREGISTER for device: %s\n" , dev, dev->name); +break ; +case NETDEV_CHANGE : +lapb_dbg (0 ,"(%p): got event NETDEV_CHANGE for device: %s\n" , dev, dev->name); + lapb =lapb_devtostruct (dev); +if (lapb) { +if (!netif_carrier_ok (dev)) { +lapb_dbg (0 ,"(%p): Carrier lost -> Entering LAPB_STATE_0: %s\n" , dev, dev->name); +lapb_disconnect_indication (lapb,LAPB_OK ); +lapb_clear_queues (lapb); + lapb->state =LAPB_STATE_0 ; + lapb->n2count =0 ; +lapb_stop_t1timer (lapb); +lapb_stop_t2timer (lapb); + }else { +lapb_dbg (0 ,"(%p): Carrier detected: %s\n" , dev, dev->name); +if (lapb->mode &LAPB_DCE ) { +lapb_start_t1timer (lapb); + }else { +if (lapb->state ==LAPB_STATE_0 ) { + lapb->state =LAPB_STATE_1 ; +lapb_establish_data_link (lapb); + } + } + } + } +break ; + } + } + +return NOTIFY_DONE ; +} + +static struct notifier_block lapb_dev_notifier = { + .notifier_call = lapb_device_event, +}; +static int __init lapb_init (void ) { +register_netdevice_notifier (&lapb_dev_notifier); +return 0 ; } static void __exit lapb_exit(void) {WARN_ON (!list_empty (&lapb_list)); + +unregister_netdevice_notifier (&lapb_dev_notifier); }MODULE_AUTHOR ("Jonathan Naylor <[email protected]>" );
Signature · 1 line
2.20.1
Martin Schiller
maintainerPATCH 6/6 net/lapb: fix t1 timer handling
In reply to Martin Schillerfix t1 timer handling in LAPB_STATE_0:
o DTE interface changes immediately to LAPB_STATE_1 and start sending SABM(E).
o DCE interface sends N2-times DM and changes to LAPB_STATE_1 afterwards if there is no response in the meantime.
--- net/lapb/lapb_timer.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
net/lapb/lapb_timer.c +7 -2
@@ -85,11 +85,16 @@ static void lapb_t1timer_expiry(struct timer_list *t)switch (lapb->state) {/* -* If we are a DCE, keep going DM .. DM .. DM +* If we are a DCE, send DM up to N2 times, then switch to STATE_1 and send SABM(E) */ case LAPB_STATE_0 : -if (lapb->mode &LAPB_DCE ) +if (lapb->mode &LAPB_DCE && lapb->n2count != lapb->n2) { + lapb->n2count++;lapb_send_control (lapb,LAPB_DM ,LAPB_POLLOFF ,LAPB_RESPONSE ); + }else { + lapb->state =LAPB_STATE_1 ; +lapb_establish_data_link (lapb); + }break ;/*
Signature · 1 line
2.20.1
Hi Martin,
Thanks for the series. To get the series applied faster, could you address the warnings and failures shown on this page?
https://patchwork.kernel.org/project/netdevbpf/list/?submitter=174539
Thanks!
To let the netdev robot know which tree this series should be applied, we can use [PATCH net-next 1/6] as the subject prefix.
Martin Schiller
maintainerQuoted 9 lines · Xie He
Hi Martin,
Thanks for the series. To get the series applied faster, could you address the warnings and failures shown on this page?
https://patchwork.kernel.org/project/netdevbpf/list/?submitter=174539
Thanks!To let the netdev robot know which tree this series should be applied, we can use [PATCH net-next 1/6] as the subject prefix.
Hi Xie!
Thanks. I will have a look at this.