The OpenNET Project / Index page

[ новости /+++ | форум | теги | ]

[FreeBSD] Патч для привязки имени PPP интерфейса к порту. (mac freebsd kernel patch ip)


<< Предыдущая ИНДЕКС Поиск в статьях src Установить закладку Перейти на закладку Следующая >>
Ключевые слова: mac, freebsd, kernel, patch, ip,  (найти похожие документы)
From: Roman V. Palagin <romanp@wuppy.net.ru> Subject: [FreeBSD] Патч для привязки имени PPP интерфейса к порту. Патчи для FreeBSD 3.x, добавляющие PPPIOCSUNIT. Без коментариев. вопросы (по существу): romanp@wuppy.net.ru KERNEL PATCH: diff -urN /usr/src/sys/net/save/if_ppp.c net/if_ppp.c --- /usr/src/sys/net/save/if_ppp.c Mon Aug 2 11:12:29 1999 +++ net/if_ppp.c Mon Aug 2 13:49:18 1999 @@ -246,26 +246,23 @@ } /* - * Allocate a ppp interface unit and initialize it. + * Initialize ppp interface unit. */ -struct ppp_softc * -pppalloc(pid) - pid_t pid; -{ - int nppp, i; +void +pppinit(sc) struct ppp_softc *sc; - - for (nppp = 0, sc = ppp_softc; nppp < NPPP; nppp++, sc++) - if (sc->sc_xfer == pid) { - sc->sc_xfer = 0; - return sc; - } - for (nppp = 0, sc = ppp_softc; nppp < NPPP; nppp++, sc++) - if (sc->sc_devp == NULL) - break; - if (nppp >= NPPP) - return NULL; - +{ + int i; + + sc->sc_ilen = 0; + sc->sc_m = NULL; + bzero(sc->sc_asyncmap, sizeof(sc->sc_asyncmap)); + sc->sc_asyncmap[0] = 0xffffffff; + sc->sc_asyncmap[3] = 0x60000000; + sc->sc_rasyncmap = 0; + sc->sc_outm = NULL; + sc->sc_if.if_flags |= IFF_RUNNING; + getmicrotime(&sc->sc_if.if_lastchange); sc->sc_flags = 0; sc->sc_mru = PPP_MRU; sc->sc_relinq = NULL; @@ -285,8 +282,6 @@ sc->sc_npqueue = NULL; sc->sc_npqtail = &sc->sc_npqueue; sc->sc_last_sent = sc->sc_last_recv = time_second; - - return sc; } /* @@ -378,10 +373,6 @@ switch (cmd) { case FIONREAD: *(int *)data = sc->sc_inq.ifq_len; - break; - - case PPPIOCGUNIT: - *(int *)data = sc->sc_if.if_unit; break; case PPPIOCGFLAGS: diff -urN /usr/src/sys/net/save/if_ppp.h net/if_ppp.h --- /usr/src/sys/net/save/if_ppp.h Mon Aug 2 11:12:29 1999 +++ net/if_ppp.h Mon Aug 2 11:08:25 1999 @@ -49,6 +49,7 @@ #define SC_LOG_OUTPKT 0x00040000 /* log contents of pkts sent */ #define SC_LOG_RAWIN 0x00080000 /* log all chars received */ #define SC_LOG_FLUSH 0x00100000 /* log all chars flushed */ +#define SC_STATIC 0x00200000 /* static unit */ #define SC_RCV_B7_0 0x01000000 /* have rcvd char with bit 7 = 0 */ #define SC_RCV_B7_1 0x02000000 /* have rcvd char with bit 7 = 1 */ #define SC_RCV_EVNP 0x04000000 /* have rcvd char with even parity */ @@ -98,7 +99,7 @@ /* * Ioctl definitions. */ - +#define PPPIOCSUNIT _IOW('t', 91, int) /* set PPP unit number */ #define PPPIOCGFLAGS _IOR('t', 90, int) /* get configuration flags */ #define PPPIOCSFLAGS _IOW('t', 89, int) /* set configuration flags */ #define PPPIOCGASYNCMAP _IOR('t', 88, int) /* get async map */ diff -urN /usr/src/sys/net/save/if_pppvar.h net/if_pppvar.h --- /usr/src/sys/net/save/if_pppvar.h Mon Aug 2 13:43:57 1999 +++ net/if_pppvar.h Mon Aug 2 16:18:11 1999 @@ -100,7 +100,7 @@ extern struct ppp_softc ppp_softc[NPPP]; -struct ppp_softc *pppalloc __P((pid_t pid)); +void pppinit __P((struct ppp_softc *sc)); void pppdealloc __P((struct ppp_softc *sc)); int pppioctl __P((struct ppp_softc *sc, u_long cmd, caddr_t data, int flag, struct proc *p)); diff -urN /usr/src/sys/net/save/ppp_tty.c net/ppp_tty.c --- /usr/src/sys/net/save/ppp_tty.c Mon Aug 2 11:12:29 1999 +++ net/ppp_tty.c Mon Aug 2 15:59:20 1999 @@ -90,6 +90,7 @@ #include <sys/conf.h> #include <sys/uio.h> #include <sys/vnode.h> +#include <sys/malloc.h> #ifdef __i386__ #include <i386/isa/intr_machdep.h> @@ -190,7 +191,7 @@ /* * Line specific open routine for async tty devices. - * Attach the given tty to the first available ppp unit. + * Just make some checks and return. * Called from device open routine or ttioctl() at >= splsofttty() */ /* ARGSUSED */ @@ -199,49 +200,25 @@ dev_t dev; register struct tty *tp; { - struct proc *p = curproc; /* XXX */ + struct proc *p = curproc; /* XXX */ register struct ppp_softc *sc; int error, s; if ((error = suser(p->p_ucred, &p->p_acflag)) != 0) return (error); - + + printf("pppopen() entered\n"); s = spltty(); - if (tp->t_line == PPPDISC) { + if (tp->t_line == PPPDISC) { /* XXX unsure */ sc = (struct ppp_softc *) tp->t_sc; if (sc != NULL && sc->sc_devp == (void *) tp) { splx(s); - return (0); + return (EBUSY); } } - if ((sc = pppalloc(p->p_pid)) == NULL) { - splx(s); - return ENXIO; - } - - if (sc->sc_relinq) - (*sc->sc_relinq)(sc); /* get previous owner to relinquish the unit */ - - sc->sc_ilen = 0; - sc->sc_m = NULL; - bzero(sc->sc_asyncmap, sizeof(sc->sc_asyncmap)); - sc->sc_asyncmap[0] = 0xffffffff; - sc->sc_asyncmap[3] = 0x60000000; - sc->sc_rasyncmap = 0; - sc->sc_devp = (void *) tp; - sc->sc_start = pppasyncstart; - sc->sc_ctlp = pppasyncctlp; - sc->sc_relinq = pppasyncrelinq; - sc->sc_setmtu = pppasyncsetmtu; - sc->sc_outm = NULL; - pppgetm(sc); - sc->sc_if.if_flags |= IFF_RUNNING; - getmicrotime(&sc->sc_if.if_lastchange); - sc->sc_if.if_baudrate = tp->t_ospeed; - - tp->t_sc = (caddr_t) sc; + tp->t_sc = (caddr_t) 0; ttyflush(tp, FREAD | FWRITE); /* @@ -250,12 +227,12 @@ * We also pass 1 byte tokens through t_canq... */ clist_alloc_cblocks(&tp->t_canq, 1, 1); - clist_alloc_cblocks(&tp->t_outq, sc->sc_if.if_mtu + PPP_HIWAT, - sc->sc_if.if_mtu + PPP_HIWAT); + clist_alloc_cblocks(&tp->t_outq, PPP_MTU + PPP_HIWAT, + PPP_MTU + PPP_HIWAT); clist_alloc_cblocks(&tp->t_rawq, 0, 0); splx(s); - + printf("pppopen() exited\n"); return (0); } @@ -464,13 +441,65 @@ struct proc *p; { struct ppp_softc *sc = (struct ppp_softc *) tp->t_sc; - int error, s; + int error, s, unit; - if (sc == NULL || tp != (struct tty *) sc->sc_devp) - return (ENOIOCTL); + if(cmd != PPPIOCSUNIT) + if(sc == NULL || tp != (struct tty *) sc->sc_devp) + return (ENOIOCTL); error = 0; switch (cmd) { + + case PPPIOCGUNIT: + *(int *)data = sc->sc_if.if_unit; + break; + + case PPPIOCSUNIT: + + + if(sc != NULL) { + error = EINVAL; + break; + } + + unit = *(int*)data; + printf("pppioctl(PPPIOCSUNIT): unit %d\n", unit); + + if(unit == -1) { /* get first free unit */ + for(unit = 0; unit < NPPP; unit++) + if(ppp_softc[unit].sc_devp == NULL) + break; + *(int*)data = unit; /* return unit number */ + } + + if( unit <0 || unit >= NPPP ) { + error = ENXIO; + break; + } + + sc = &ppp_softc[unit]; + + if(sc->sc_devp != NULL) { + error = EBUSY; + break; + } + + pppinit(sc); + sc->sc_start = pppasyncstart; + sc->sc_ctlp = pppasyncctlp; + sc->sc_relinq = pppasyncrelinq; + sc->sc_setmtu = pppasyncsetmtu; + sc->sc_devp = (void *) tp; + sc->sc_if.if_baudrate = tp->t_ospeed; + pppgetm(sc); + tp->t_sc = (caddr_t)sc; +#ifdef notyet + if (sc->sc_relinq) + (*sc->sc_relinq)(sc); /* get previous owner to relinquish the unit */ +#endif + + break; + case PPPIOCSASYNCMAP: if ((error = suser(p->p_ucred, &p->p_acflag)) != 0) break; PPPD PATCH: diff -urN /usr/src/usr.sbin/pppd/Makefile pppd/Makefile --- /usr/src/usr.sbin/pppd/Makefile Sat Jul 31 18:08:34 1999 +++ pppd/Makefile Mon Aug 2 11:43:05 1999 @@ -1,6 +1,6 @@ # $Id: Makefile,v 1.12.2.1 1999/05/07 04:29:04 jdp Exp $ -CFLAGS+= -DHAVE_PATHS_H +CFLAGS+= -g -DHAVE_PATHS_H PROG= pppd SRCS= main.c magic.c fsm.c lcp.c ipcp.c ipxcp.c upap.c chap.c ccp.c \ diff -urN /usr/src/usr.sbin/pppd/main.c pppd/main.c --- /usr/src/usr.sbin/pppd/main.c Sat Jul 31 18:08:34 1999 +++ pppd/main.c Mon Aug 2 16:49:54 1999 @@ -72,7 +72,6 @@ /* interface vars */ char ifname[32]; /* Interface name */ -int ifunit; /* Interface unit number */ char *progname; /* Name of this program */ char hostname[MAXNAMELEN]; /* Our hostname */ diff -urN /usr/src/usr.sbin/pppd/options.c pppd/options.c --- /usr/src/usr.sbin/pppd/options.c Sat Jul 31 18:08:34 1999 +++ pppd/options.c Mon Aug 2 16:50:21 1999 @@ -85,6 +85,7 @@ int kdebugflag = 0; /* Tell kernel to print debug messages */ int default_device = 1; /* Using /dev/tty or equivalent */ char devnam[MAXPATHLEN] = "/dev/tty"; /* Device name */ +int ifunit = -1; /* PPP iface unit number, if -1 - auto */ int crtscts = 0; /* Use hardware flow control */ int modem = 1; /* Use modem control lines */ int inspeed = 0; /* Input/Output speed requested */ @@ -138,6 +139,7 @@ * Prototypes */ static int setdevname __P((char *, int)); +static int setpppunit __P((char **)); static int setspeed __P((char *)); static int setdebug __P((char **)); static int setkdebug __P((char **)); @@ -285,6 +287,7 @@ int num_args; int (*cmd_func) __P((char **)); } cmds[] = { + {"pppunit",1,setpppunit}, /* Set PPP iface number */ {"-all", 0, noopt}, /* Don't request/allow any options (useless) */ {"noaccomp", 0, noaccomp}, /* Disable Address/Control compression */ {"-ac", 0, noaccomp}, /* Disable Address/Control compress */ @@ -1308,6 +1311,19 @@ return (1); } +/* + * setpppunit - Set PPP unit number. + */ +static int +setpppunit(argv) + char **argv; +{ + int unit; + if (!number_option(*argv, &unit, 0)) + return 0; + ifunit = unit; + return (1); +} /* * setmru - Set the largest MTU we'll use. diff -urN /usr/src/usr.sbin/pppd/patchlevel.h pppd/patchlevel.h --- /usr/src/usr.sbin/pppd/patchlevel.h Sat Jun 20 22:02:14 1998 +++ pppd/patchlevel.h Mon Aug 2 16:48:18 1999 @@ -2,5 +2,5 @@ #define PATCHLEVEL 5 #define VERSION "2.3" -#define IMPLEMENTATION "" -#define DATE "4 May 1998" +#define IMPLEMENTATION "-PPPIOCSUNIT" +#define DATE "02 Aug 1999" diff -urN /usr/src/usr.sbin/pppd/sys-bsd.c pppd/sys-bsd.c --- /usr/src/usr.sbin/pppd/sys-bsd.c Sat Jul 31 18:08:34 1999 +++ pppd/sys-bsd.c Mon Aug 2 13:56:58 1999 @@ -236,10 +236,19 @@ } if (!demand) { + + /* + * Allocate async PPP unit + */ + if (ioctl(fd, PPPIOCSUNIT, &ifunit) < 0) { + syslog(LOG_ERR, "ioctl(PPPIOCSUNIT): %m"); + die(1); + } + /* * Find out which interface we were given. */ - if (ioctl(fd, PPPIOCGUNIT, &ifunit) < 0) { + if (ioctl(fd, PPPIOCGUNIT, &ifunit) < 0) { syslog(LOG_ERR, "ioctl(PPPIOCGUNIT): %m"); die(1); }

<< Предыдущая ИНДЕКС Поиск в статьях src Установить закладку Перейти на закладку Следующая >>

 Добавить комментарий
Имя:
E-Mail:
Заголовок:
Текст:




Партнёры:
PostgresPro
Inferno Solutions
Hosting by Hoster.ru
Хостинг:

Закладки на сайте
Проследить за страницей
Created 1996-2024 by Maxim Chirkov
Добавить, Поддержать, Вебмастеру