Module Name: src Committed By: pgoyette Date: Tue Mar 26 00:23:32 UTC 2019
Modified Files: src/sys/net: if_srt.c Log Message: Add devsw_{attach,detach} stuff for _MODULE variant. (Not needed for built-in variant since the devsw is also built-in.) This will allow the modular srt devices to be accessed via open(2) and ioctl(2). XXX Someone(tm) needs to update MAKEDEV to create the /dev/srtN device nodes (with device-major 179)! To generate a diff of this commit: cvs rdiff -u -r1.27 -r1.28 src/sys/net/if_srt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/net/if_srt.c diff -u src/sys/net/if_srt.c:1.27 src/sys/net/if_srt.c:1.28 --- src/sys/net/if_srt.c:1.27 Mon Oct 23 09:32:55 2017 +++ src/sys/net/if_srt.c Tue Mar 26 00:23:32 2019 @@ -1,8 +1,8 @@ -/* $NetBSD: if_srt.c,v 1.27 2017/10/23 09:32:55 msaitoh Exp $ */ +/* $NetBSD: if_srt.c,v 1.28 2019/03/26 00:23:32 pgoyette Exp $ */ /* This file is in the public domain. */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_srt.c,v 1.27 2017/10/23 09:32:55 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_srt.c,v 1.28 2019/03/26 00:23:32 pgoyette Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -64,6 +64,29 @@ static unsigned int global_flags; static u_int srt_count; +#ifdef _MODULE +devmajor_t srt_bmajor = -1, srt_cmajor = -1; +#endif + +static int srt_open(dev_t, int, int, struct lwp *); +static int srt_close(dev_t, int, int, struct lwp *); +static int srt_ioctl(dev_t, u_long, void *, int, struct lwp *); + +const struct cdevsw srt_cdevsw = { + .d_open = srt_open, + .d_close = srt_close, + .d_read = nullread, + .d_write = nullwrite, + .d_ioctl = srt_ioctl, + .d_stop = nullstop, + .d_tty = notty, + .d_poll = nullpoll, + .d_mmap = nommap, + .d_kqfilter = nullkqfilter, + .d_discard = nodiscard, + .d_flag = D_OTHER +}; + /* Internal routines. */ static unsigned int ipv4_masks[33] = { @@ -332,6 +355,9 @@ srtinit(void) softcv[i] = 0; global_flags = 0; if_clone_attach(&srt_clone); +#ifdef _MODULE + devsw_attach("srt", NULL, &srt_bmajor, &srt_cdevsw, &srt_cmajor); +#endif } static int @@ -340,15 +366,26 @@ srtdetach(void) int error = 0; int i; + if_clone_detach(&srt_clone); +#ifdef _MODULE + devsw_detach(NULL, &srt_cdevsw); + if (error != 0) { + if_clone_attach(&srt_clone); + return error; + } +#endif + for (i = SRT_MAXUNIT; i >= 0; i--) if(softcv[i]) { error = EBUSY; +#ifdef _MODULE + devsw_attach("srt", NULL, &srt_bmajor, + &srt_cdevsw, &srt_cmajor); +#endif + if_clone_attach(&srt_clone); break; } - if (error == 0) - if_clone_detach(&srt_clone); - return error; } @@ -533,21 +570,6 @@ srt_ioctl(dev_t dev, u_long cmd, void *d return ENOTTY; } -const struct cdevsw srt_cdevsw = { - .d_open = srt_open, - .d_close = srt_close, - .d_read = nullread, - .d_write = nullwrite, - .d_ioctl = srt_ioctl, - .d_stop = nullstop, - .d_tty = notty, - .d_poll = nullpoll, - .d_mmap = nommap, - .d_kqfilter = nullkqfilter, - .d_discard = nodiscard, - .d_flag = D_OTHER -}; - /* * Module infrastructure */