[patch] Fix for PPP/SLIP driver

From: Stanislav V. Voronyi (stas@esc.kharkov.com)
Date: Wed Feb 02 2000 - 17:54:48 EST


        I work at quite big ISP all running linux and after
upgrade from 2.0 to 2.2 kernel we found a problem: if pppd or
slcall was killed by SIGKILL for instance, network interface
still up and it is very bad for Radius server because Radius
decide that IP# which was used on this interface freed and can
be used further. But since interface still UP gated continued
to announce this address through OSPF.
        From other side if I would do ifconfig pppXX down or
ifconfig slXX down control programm (pppd or slcall) receive
no notification about it. If slip driver compiled with my
CONFIG_SLIP_SMART option and keepalive function activated
it will force hangup after keepalive timeout. For ppp or slip
without keepalive option activated control programm still
running until modem force hangup by inactivity timer.

        I've made patch for kernel 2.2.14 and send it to mailing
lists before. I look at kernel 2.3 and found that rewriting of
ppp driver fix one of this problem - if control problem was killed
driver will close network interface. But closing of interface does
not lead to notification of control programm. SLIP driver still have
both problems.

        I fix this problems in SLIP driver in the same way as in 2.2.14
kernel. But since PPP driver in 2.3 kernel was changed I found only one
possible way to fix problem - save pgrp of control process when interface
going UP and send SIGHUP to this process group on interface closing.
        
        Here is the patch for clean 2.3.40 kernel:

diff -u --recursive linux.dist/CREDITS linux/CREDITS
--- linux.dist/CREDITS Sun Jan 30 02:23:50 2000
+++ linux/CREDITS Wed Feb 2 23:27:08 2000
@@ -2255,6 +2255,16 @@
 S: Moorhead, Minnesota 56560
 S: USA
 
+N: Stanislav Voronyi
+E: stas@esc.kharkov.com
+D: SLIP linefill/keepalive option
+D: SLIP/PPP interface behaviour fix
+D: Console driver hacks
+D: AWE 3DSE support
+W: http://esc.kharkov.com/stas/
+S: ap4, 5, Kashuby st.
+S: Kharkov, Ukraine, 61034
+
 N: Jos Vos
 E: jos@xos.nl
 W: http://www.xos.nl/
diff -u --recursive linux.dist/drivers/net/ppp_generic.c linux/drivers/net/ppp_generic.c
--- linux.dist/drivers/net/ppp_generic.c Tue Nov 9 21:50:49 1999
+++ linux/drivers/net/ppp_generic.c Wed Feb 2 23:10:37 2000
@@ -28,6 +28,8 @@
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/kmod.h>
+#include <linux/signal.h>
+#include <linux/sched.h>
 #include <linux/init.h>
 #include <linux/list.h>
 #include <linux/netdevice.h>
@@ -97,6 +99,7 @@
         unsigned long last_recv; /* jiffies when last pkt rcvd */
         struct net_device *dev; /* network interface device */
         struct net_device_stats stats; /* statistics */
+ pid_t pppd_pgrp; /* pgrp of control process */
 };
 
 static LIST_HEAD(all_ppp_units);
@@ -696,6 +699,33 @@
         return err;
 }
 
+int ppp_net_open(struct net_device *dev)
+{
+ struct ppp *ppp;
+
+ dev->start = 1;
+ /* remember control process pgrp */
+ ppp = dev->priv;
+ ppp->pppd_pgrp = current->pgrp;
+ return 0;
+}
+
+int ppp_net_close(struct net_device *dev)
+{
+ struct ppp *ppp;
+
+ if (dev->start) {
+ dev->start = 0;
+ ppp = (struct ppp *)dev->priv;
+ /* try to notify control program about interface shutdown
+ send SIGHUP to it.
+ -- Stanislav Voronyi. */
+ if (ppp->pppd_pgrp)
+ kill_pg(ppp->pppd_pgrp, SIGHUP, 1);
+ }
+ return 0;
+}
+
 int
 ppp_net_init(struct net_device *dev)
 {
@@ -703,6 +733,8 @@
         dev->mtu = PPP_MTU;
         dev->hard_start_xmit = ppp_start_xmit;
         dev->get_stats = ppp_net_stats;
+ dev->stop = ppp_net_close;
+ dev->open = ppp_net_open;
         dev->do_ioctl = ppp_net_ioctl;
         dev->addr_len = 0;
         dev->tx_queue_len = 3;
@@ -1556,6 +1588,11 @@
            mark the interface down, free the ppp unit */
         if (ppp->dev) {
                 rtnl_lock();
+ /* Since dev_close() will call ppp_net_close() to prevent
+ undesirable sending of SIGHUP to control process set
+ dev->start to 0 before calling dev_close()
+ -- Stanislav Voronyi */
+ ppp->dev->start = 0;
                 dev_close(ppp->dev);
                 rtnl_unlock();
         }
diff -u --recursive linux.dist/drivers/net/slip.c linux/drivers/net/slip.c
--- linux.dist/drivers/net/slip.c Tue Nov 9 18:20:12 1999
+++ linux/drivers/net/slip.c Wed Feb 2 23:21:41 2000
@@ -52,6 +52,7 @@
  * have been ported to Linux SLIP driver.
  * Vitaly E. Lavrov : Sane behaviour on tty hangup.
  * Alexey Kuznetsov : Cleanup interfaces to tty&netdevice modules.
+ * Stanislav Voronyi : Sane behaviour on interface down / line discipline change
  */
 
 #define SL_CHECK_TRANSMIT
@@ -550,6 +551,10 @@
         sl->rcount = 0;
         sl->xleft = 0;
         end_bh_atomic();
+ /* If netdevice going down first -> force hangup
+ -- Stanislav Voronyi */
+ if (sl->tty)
+ tty_hangup(sl->tty);
 
         MOD_DEC_USE_COUNT;
         return 0;
@@ -925,6 +930,13 @@
  */
 
 /*
+ I found that this function called from tty_set_ldisc()
+ before setting new discipline.
+ So we can close netdevice if line discipline was changed.
+ -- Stanislav Voronyi. (VSV)
+*/
+
+/*
  * Close down a SLIP channel.
  * This means flushing out any pending queues, and then restoring the
  * TTY line discipline to what it was before it got hooked to SLIP
@@ -943,6 +955,15 @@
         sl->tty = NULL;
         if (!sl->leased)
                 sl->line = 0;
+
+ /* down interface if it is UP first
+ -- VSV */
+ if (sl->dev->start){
+ rtnl_lock();
+ dev_close(sl->dev);
+ rtnl_unlock();
+ }
+ /* VSV changes end */
 
         /* VSV = very important to remove timers */
 #ifdef CONFIG_SLIP_SMART

-- 
Stanislav V. Voroniy                            |Tel. +380 (572) 128302
Head of System Administration Department        |                210901
Centre of Information Technologies "Vostok" Ltd.|Fax. +380 (572) 213117

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Mon Feb 07 2000 - 21:00:08 EST