Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/pppd/pppd Add a set_queue_size to avoid more code d...



details:   https://anonhg.NetBSD.org/src/rev/077d4e00b0af
branches:  trunk
changeset: 787576:077d4e00b0af
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Jun 24 20:43:48 2013 +0000

description:
Add a set_queue_size to avoid more code duplication, and set the queue size
of all tty fd's, not just the ones that we create (the ones that we get passed
in too). Fixes my iPhone -> xl2tpd -> pppd VPN from corrupting packets with
MTU > ~650.

diffstat:

 usr.sbin/pppd/pppd/sys-bsd.c |  41 ++++++++++++++++++++++++++++++-----------
 1 files changed, 30 insertions(+), 11 deletions(-)

diffs (102 lines):

diff -r cdc97c920bef -r 077d4e00b0af usr.sbin/pppd/pppd/sys-bsd.c
--- a/usr.sbin/pppd/pppd/sys-bsd.c      Mon Jun 24 19:43:58 2013 +0000
+++ b/usr.sbin/pppd/pppd/sys-bsd.c      Mon Jun 24 20:43:48 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sys-bsd.c,v 1.67 2013/06/08 13:13:34 christos Exp $    */
+/*     $NetBSD: sys-bsd.c,v 1.68 2013/06/24 20:43:48 christos Exp $    */
 
 /*
  * sys-bsd.c - System-dependent procedures for setting up
@@ -79,7 +79,7 @@
 #if 0
 #define RCSID  "Id: sys-bsd.c,v 1.47 2000/04/13 12:04:23 paulus Exp "
 #else
-__RCSID("$NetBSD: sys-bsd.c,v 1.67 2013/06/08 13:13:34 christos Exp $");
+__RCSID("$NetBSD: sys-bsd.c,v 1.68 2013/06/24 20:43:48 christos Exp $");
 #endif
 #endif
 
@@ -201,6 +201,27 @@
 static void restore_loop(void);        /* Transfer ppp unit back to loopback */
 
 
+static void
+set_queue_size(const char *fmt, int fd) {
+#ifdef TIOCSQSIZE
+    int oqsize, qsize = 32768;
+
+    /* Only for ptys */
+    if (ioctl(fd, TIOCGQSIZE, &oqsize) == -1)
+       return;
+
+    if (oqsize >= qsize)
+       return;
+
+    if (ioctl(fd, TIOCSQSIZE, &qsize) == -1)
+       warn("%s: Cannot set tty queue size for %d from %d to %d", fmt, fd,
+           oqsize, qsize);
+    else
+       notice("%s: Changed queue size of %d from %d to %d", fmt, fd, oqsize,
+           qsize);
+#endif
+}
+
 /********************************************************************
  *
  * Functions to read and set the flags value in the device driver
@@ -386,6 +407,7 @@
            fatal("%s: ioctl(transfer ppp unit): %m", __func__);
     }
 
+    set_queue_size(__func__, fd);
     /*
      * Save the old line discipline of fd, and set it to PPP.
      */
@@ -443,6 +465,7 @@
 {
     int x;
 
+    set_queue_size(__func__, loop_slave);
     /*
      * Transfer the ppp interface back to the loopback.
      */
@@ -645,6 +668,7 @@
     }
 }
 
+
 /*
  * set_up_tty: Set up the serial port on `fd' for 8 bits, no parity,
  * at the requested speed, etc.  If `local' is true, set CLOCAL
@@ -665,6 +689,8 @@
        ioctl(fd, TIOCGWINSZ, &wsinfo);
     }
 
+    set_queue_size(__func__, fd);
+
     tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB | CLOCAL);
     if (crtscts > 0 && !local) {
         if (crtscts == 2) {
@@ -931,20 +957,13 @@
 int
 get_pty(int *master_fdp, int *slave_fdp, char *slave_name, int uid)
 {
-#ifdef TIOCSQSIZE
-    int qsize = 32768;
-#endif
     struct termios tios;
 
     if (openpty(master_fdp, slave_fdp, slave_name, NULL, NULL) < 0)
        return 0;
 
-#ifdef TIOCSQSIZE
-    if (ioctl(*master_fdp, TIOCSQSIZE, &qsize) == -1)
-       warn("%s: couldn't set master queue size: %m", __func__);
-    if (ioctl(*slave_fdp, TIOCSQSIZE, &qsize) == -1)
-       warn("%s: couldn't set slave queue size: %m", __func__);
-#endif
+    set_queue_size(__func__, *master_fdp);
+    set_queue_size(__func__, *slave_fdp);
     fchown(*slave_fdp, uid, -1);
     fchmod(*slave_fdp, S_IRUSR | S_IWUSR);
     if (tcgetattr(*slave_fdp, &tios) == 0) {



Home | Main Index | Thread Index | Old Index