2 * Copyright (C) 1999-2000 by Maksim Yevmenkin <m_evmenkin@yahoo.com>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * -------------------------------------------------------------------------
29 * Copyright (c) 1988, Julian Onions <jpo@cs.nott.ac.uk>
30 * Nottingham University 1987.
35 * $Id: if_tap.c,v 0.21 2000/07/23 21:46:02 max Exp $
38 #include "opt_compat.h"
41 #include <sys/param.h>
43 #include <sys/fcntl.h>
44 #include <sys/filio.h>
45 #include <sys/kernel.h>
46 #include <sys/malloc.h>
48 #include <sys/module.h>
52 #include <sys/selinfo.h>
53 #include <sys/signalvar.h>
54 #include <sys/socket.h>
55 #include <sys/sockio.h>
56 #include <sys/sysctl.h>
57 #include <sys/systm.h>
58 #include <sys/ttycom.h>
60 #include <sys/queue.h>
63 #include <net/ethernet.h>
65 #include <net/if_dl.h>
66 #include <net/route.h>
67 #include <net/if_types.h>
69 #include <netinet/in.h>
71 #include <net/if_tapvar.h>
72 #include <net/if_tap.h>
75 #define CDEV_NAME "tap"
76 #define TAPDEBUG if (tapdebug) printf
80 #define TAPMAXUNIT 0x7fff
81 #define VMNET_DEV_MASK CLONE_FLAG0
84 static int tapmodevent(module_t, int, void *);
87 static void tapclone(void *, struct ucred *, char *, int,
89 static void tapcreate(struct cdev *);
91 /* network interface */
92 static void tapifstart(struct ifnet *);
93 static int tapifioctl(struct ifnet *, u_long, caddr_t);
94 static void tapifinit(void *);
96 /* character device */
97 static d_open_t tapopen;
98 static d_close_t tapclose;
99 static d_read_t tapread;
100 static d_write_t tapwrite;
101 static d_ioctl_t tapioctl;
102 static d_poll_t tappoll;
103 static d_kqfilter_t tapkqfilter;
106 static int tapkqread(struct knote *, long);
107 static int tapkqwrite(struct knote *, long);
108 static void tapkqdetach(struct knote *);
110 static struct filterops tap_read_filterops = {
113 .f_detach = tapkqdetach,
114 .f_event = tapkqread,
117 static struct filterops tap_write_filterops = {
120 .f_detach = tapkqdetach,
121 .f_event = tapkqwrite,
124 static struct cdevsw tap_cdevsw = {
125 .d_version = D_VERSION,
126 .d_flags = D_PSEUDO | D_NEEDGIANT,
134 .d_kqfilter = tapkqfilter,
138 * All global variables in if_tap.c are locked with tapmtx, with the
139 * exception of tapdebug, which is accessed unlocked; tapclones is
142 static struct mtx tapmtx;
143 static int tapdebug = 0; /* debug flag */
144 static int tapuopen = 0; /* allow user open() */
145 static SLIST_HEAD(, tap_softc) taphead; /* first device */
146 static struct clonedevs *tapclones;
148 MALLOC_DECLARE(M_TAP);
149 MALLOC_DEFINE(M_TAP, CDEV_NAME, "Ethernet tunnel interface");
150 SYSCTL_INT(_debug, OID_AUTO, if_tap_debug, CTLFLAG_RW, &tapdebug, 0, "");
152 SYSCTL_DECL(_net_link);
153 SYSCTL_NODE(_net_link, OID_AUTO, tap, CTLFLAG_RW, 0,
154 "Ethernet tunnel software network interface");
155 SYSCTL_INT(_net_link_tap, OID_AUTO, user_open, CTLFLAG_RW, &tapuopen, 0,
156 "Allow user to open /dev/tap (based on node permissions)");
157 SYSCTL_INT(_net_link_tap, OID_AUTO, debug, CTLFLAG_RW, &tapdebug, 0, "");
159 DEV_MODULE(if_tap, tapmodevent, NULL);
164 * module event handler
167 tapmodevent(module_t mod, int type, void *data)
169 static eventhandler_tag eh_tag = NULL;
170 struct tap_softc *tp = NULL;
171 struct ifnet *ifp = NULL;
177 /* intitialize device */
179 mtx_init(&tapmtx, "tapmtx", NULL, MTX_DEF);
180 SLIST_INIT(&taphead);
182 clone_setup(&tapclones);
183 eh_tag = EVENTHANDLER_REGISTER(dev_clone, tapclone, 0, 1000);
184 if (eh_tag == NULL) {
185 clone_cleanup(&tapclones);
186 mtx_destroy(&tapmtx);
193 * The EBUSY algorithm here can't quite atomically
194 * guarantee that this is race-free since we have to
195 * release the tap mtx to deregister the clone handler.
198 SLIST_FOREACH(tp, &taphead, tap_next) {
199 mtx_lock(&tp->tap_mtx);
200 if (tp->tap_flags & TAP_OPEN) {
201 mtx_unlock(&tp->tap_mtx);
205 mtx_unlock(&tp->tap_mtx);
209 EVENTHANDLER_DEREGISTER(dev_clone, eh_tag);
212 while ((tp = SLIST_FIRST(&taphead)) != NULL) {
213 SLIST_REMOVE_HEAD(&taphead, tap_next);
218 TAPDEBUG("detaching %s\n", ifp->if_xname);
221 KASSERT(!(tp->tap_flags & TAP_OPEN),
222 ("%s flags is out of sync", ifp->if_xname));
224 knlist_destroy(&tp->tap_rsel.si_note);
225 destroy_dev(tp->tap_dev);
228 if_free_type(ifp, IFT_ETHER);
231 mtx_destroy(&tp->tap_mtx);
236 clone_cleanup(&tapclones);
238 mtx_destroy(&tapmtx);
253 * We need to support two kind of devices - tap and vmnet
256 tapclone(void *arg, struct ucred *cred, char *name, int namelen, struct cdev **dev)
260 char *device_name = name;
267 if (strcmp(name, TAP) == 0) {
269 } else if (strcmp(name, VMNET) == 0) {
271 extra = VMNET_DEV_MASK;
273 } else if (dev_stdclone(name, NULL, device_name, &unit) != 1) {
275 extra = VMNET_DEV_MASK;
276 if (dev_stdclone(name, NULL, device_name, &unit) != 1)
280 /* find any existing device, or allocate new unit number */
281 i = clone_create(&tapclones, &tap_cdevsw, &unit, dev, extra);
283 *dev = make_dev(&tap_cdevsw, unit2minor(unit | extra),
284 UID_ROOT, GID_WHEEL, 0600, "%s%d", device_name, unit);
287 (*dev)->si_flags |= SI_CHEAPCLONE;
296 * to create interface
299 tapcreate(struct cdev *dev)
301 struct ifnet *ifp = NULL;
302 struct tap_softc *tp = NULL;
303 unsigned short macaddr_hi;
308 dev->si_flags &= ~SI_CHEAPCLONE;
310 /* allocate driver storage and create device */
311 MALLOC(tp, struct tap_softc *, sizeof(*tp), M_TAP, M_WAITOK | M_ZERO);
312 mtx_init(&tp->tap_mtx, "tap_mtx", NULL, MTX_DEF);
314 SLIST_INSERT_HEAD(&taphead, tp, tap_next);
317 unit = dev2unit(dev);
319 /* select device: tap or vmnet */
320 if (unit & VMNET_DEV_MASK) {
322 tp->tap_flags |= TAP_VMNET;
328 TAPDEBUG("tapcreate(%s%d). minor = %#x\n", name, unit, minor(dev));
330 /* generate fake MAC address: 00 bd xx xx xx unit_no */
331 macaddr_hi = htons(0x00bd);
332 bcopy(&macaddr_hi, eaddr, sizeof(short));
333 bcopy(&ticks, &eaddr[2], sizeof(long));
334 eaddr[5] = (u_char)unit;
336 /* fill the rest and attach interface */
337 ifp = tp->tap_ifp = if_alloc(IFT_ETHER);
339 panic("%s%d: can not if_alloc()", name, unit);
341 if_initname(ifp, name, unit);
342 ifp->if_init = tapifinit;
343 ifp->if_start = tapifstart;
344 ifp->if_ioctl = tapifioctl;
345 ifp->if_mtu = ETHERMTU;
346 ifp->if_flags = (IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST);
347 ifp->if_snd.ifq_maxlen = ifqmaxlen;
353 ether_ifattach(ifp, eaddr);
356 mtx_lock(&tp->tap_mtx);
357 tp->tap_flags |= TAP_INITED;
358 mtx_unlock(&tp->tap_mtx);
360 knlist_init(&tp->tap_rsel.si_note, NULL, NULL, NULL, NULL);
362 TAPDEBUG("interface %s is created. minor = %#x\n",
363 ifp->if_xname, minor(dev));
370 * to open tunnel. must be superuser
373 tapopen(struct cdev *dev, int flag, int mode, struct thread *td)
375 struct tap_softc *tp = NULL;
376 struct ifnet *ifp = NULL;
380 error = priv_check(td, PRIV_NET_TAP);
385 if ((dev2unit(dev) & CLONE_UNITMASK) > TAPMAXUNIT)
389 * XXXRW: Non-atomic test-and-set of si_drv1. Currently protected
390 * by Giant, but the race actually exists under memory pressure as
391 * well even when running with Giant, as malloc() may sleep.
399 mtx_lock(&tp->tap_mtx);
400 if (tp->tap_flags & TAP_OPEN) {
401 mtx_unlock(&tp->tap_mtx);
405 bcopy(IF_LLADDR(tp->tap_ifp), tp->ether_addr, sizeof(tp->ether_addr));
406 tp->tap_pid = td->td_proc->p_pid;
407 tp->tap_flags |= TAP_OPEN;
409 mtx_unlock(&tp->tap_mtx);
412 ifp->if_drv_flags |= IFF_DRV_RUNNING;
413 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
416 TAPDEBUG("%s is open. minor = %#x\n", ifp->if_xname, minor(dev));
425 * close the device - mark i/f down & delete routing info
428 tapclose(struct cdev *dev, int foo, int bar, struct thread *td)
431 struct tap_softc *tp = dev->si_drv1;
432 struct ifnet *ifp = tp->tap_ifp;
435 /* junk all pending output */
436 IF_DRAIN(&ifp->if_snd);
439 * do not bring the interface down, and do not anything with
440 * interface, if we are in VMnet mode. just close the device.
443 mtx_lock(&tp->tap_mtx);
444 if (((tp->tap_flags & TAP_VMNET) == 0) && (ifp->if_flags & IFF_UP)) {
445 mtx_unlock(&tp->tap_mtx);
448 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
449 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
450 rtinit(ifa, (int)RTM_DELETE, 0);
453 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
457 mtx_unlock(&tp->tap_mtx);
459 funsetown(&tp->tap_sigio);
460 selwakeuppri(&tp->tap_rsel, PZERO+1);
461 KNOTE_UNLOCKED(&tp->tap_rsel.si_note, 0);
463 mtx_lock(&tp->tap_mtx);
464 tp->tap_flags &= ~TAP_OPEN;
466 mtx_unlock(&tp->tap_mtx);
468 TAPDEBUG("%s is closed. minor = %#x\n",
469 ifp->if_xname, minor(dev));
478 * network interface initialization function
483 struct tap_softc *tp = (struct tap_softc *)xtp;
484 struct ifnet *ifp = tp->tap_ifp;
486 TAPDEBUG("initializing %s\n", ifp->if_xname);
488 ifp->if_drv_flags |= IFF_DRV_RUNNING;
489 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
491 /* attempt to start output */
499 * Process an ioctl request on network interface
502 tapifioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
504 struct tap_softc *tp = ifp->if_softc;
505 struct ifstat *ifs = NULL;
509 case SIOCSIFFLAGS: /* XXX -- just like vmnet does */
516 ifs = (struct ifstat *)data;
517 dummy = strlen(ifs->ascii);
518 mtx_lock(&tp->tap_mtx);
519 if (tp->tap_pid != 0 && dummy < sizeof(ifs->ascii))
520 snprintf(ifs->ascii + dummy,
521 sizeof(ifs->ascii) - dummy,
522 "\tOpened by PID %d\n", tp->tap_pid);
523 mtx_unlock(&tp->tap_mtx);
529 dummy = ether_ioctl(ifp, cmd, data);
542 * queue packets from higher level ready to put out
545 tapifstart(struct ifnet *ifp)
547 struct tap_softc *tp = ifp->if_softc;
550 TAPDEBUG("%s starting\n", ifp->if_xname);
553 * do not junk pending output if we are in VMnet mode.
554 * XXX: can this do any harm because of queue overflow?
557 mtx_lock(&tp->tap_mtx);
558 if (((tp->tap_flags & TAP_VMNET) == 0) &&
559 ((tp->tap_flags & TAP_READY) != TAP_READY)) {
560 struct mbuf *m = NULL;
562 mtx_unlock(&tp->tap_mtx);
565 TAPDEBUG("%s not ready, tap_flags = 0x%x\n", ifp->if_xname,
570 IF_DEQUEUE(&ifp->if_snd, m);
579 mtx_unlock(&tp->tap_mtx);
582 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
584 if (ifp->if_snd.ifq_len != 0) {
585 mtx_lock(&tp->tap_mtx);
586 if (tp->tap_flags & TAP_RWAIT) {
587 tp->tap_flags &= ~TAP_RWAIT;
591 if ((tp->tap_flags & TAP_ASYNC) && (tp->tap_sigio != NULL)) {
592 mtx_unlock(&tp->tap_mtx);
593 pgsigio(&tp->tap_sigio, SIGIO, 0);
595 mtx_unlock(&tp->tap_mtx);
597 selwakeuppri(&tp->tap_rsel, PZERO+1);
598 KNOTE_UNLOCKED(&tp->tap_rsel.si_note, 0);
599 ifp->if_opackets ++; /* obytes are counted in ether_output */
602 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
610 * the cdevsw interface is now pretty minimal
613 tapioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td)
615 struct tap_softc *tp = dev->si_drv1;
616 struct ifnet *ifp = tp->tap_ifp;
617 struct tapinfo *tapp = NULL;
620 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
621 defined(COMPAT_FREEBSD4)
628 tapp = (struct tapinfo *)data;
629 ifp->if_mtu = tapp->mtu;
630 ifp->if_type = tapp->type;
631 ifp->if_baudrate = tapp->baudrate;
636 tapp = (struct tapinfo *)data;
637 tapp->mtu = ifp->if_mtu;
638 tapp->type = ifp->if_type;
639 tapp->baudrate = ifp->if_baudrate;
643 tapdebug = *(int *)data;
647 *(int *)data = tapdebug;
655 mtx_lock(&tp->tap_mtx);
657 tp->tap_flags |= TAP_ASYNC;
659 tp->tap_flags &= ~TAP_ASYNC;
660 mtx_unlock(&tp->tap_mtx);
666 if (ifp->if_snd.ifq_head) {
667 struct mbuf *mb = ifp->if_snd.ifq_head;
669 for(*(int *)data = 0;mb != NULL;mb = mb->m_next)
670 *(int *)data += mb->m_len;
677 return (fsetown(*(int *)data, &tp->tap_sigio));
680 *(int *)data = fgetown(&tp->tap_sigio);
683 /* this is deprecated, FIOSETOWN should be used instead */
685 return (fsetown(-(*(int *)data), &tp->tap_sigio));
687 /* this is deprecated, FIOGETOWN should be used instead */
689 *(int *)data = -fgetown(&tp->tap_sigio);
692 /* VMware/VMnet port ioctl's */
694 case SIOCGIFFLAGS: /* get ifnet flags */
695 bcopy(&ifp->if_flags, data, sizeof(ifp->if_flags));
698 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
699 defined(COMPAT_FREEBSD4)
701 ival = IOCPARM_IVAL(data);
702 data = (caddr_t)&ival;
705 case VMIO_SIOCSIFFLAGS: /* VMware/VMnet SIOCSIFFLAGS */
708 f &= ~IFF_CANTCHANGE;
712 ifp->if_flags = f | (ifp->if_flags & IFF_CANTCHANGE);
716 case OSIOCGIFADDR: /* get MAC address of the remote side */
718 mtx_lock(&tp->tap_mtx);
719 bcopy(tp->ether_addr, data, sizeof(tp->ether_addr));
720 mtx_unlock(&tp->tap_mtx);
723 case SIOCSIFADDR: /* set MAC address of the remote side */
724 mtx_lock(&tp->tap_mtx);
725 bcopy(data, tp->ether_addr, sizeof(tp->ether_addr));
726 mtx_unlock(&tp->tap_mtx);
739 * the cdevsw read interface - reads a packet at a time, or at
740 * least as much of a packet as can be read
743 tapread(struct cdev *dev, struct uio *uio, int flag)
745 struct tap_softc *tp = dev->si_drv1;
746 struct ifnet *ifp = tp->tap_ifp;
747 struct mbuf *m = NULL;
748 int error = 0, len, s;
750 TAPDEBUG("%s reading, minor = %#x\n", ifp->if_xname, minor(dev));
752 mtx_lock(&tp->tap_mtx);
753 if ((tp->tap_flags & TAP_READY) != TAP_READY) {
754 mtx_unlock(&tp->tap_mtx);
757 TAPDEBUG("%s not ready. minor = %#x, tap_flags = 0x%x\n",
758 ifp->if_xname, minor(dev), tp->tap_flags);
763 tp->tap_flags &= ~TAP_RWAIT;
764 mtx_unlock(&tp->tap_mtx);
766 /* sleep until we get a packet */
769 IF_DEQUEUE(&ifp->if_snd, m);
773 if (flag & O_NONBLOCK)
774 return (EWOULDBLOCK);
776 mtx_lock(&tp->tap_mtx);
777 tp->tap_flags |= TAP_RWAIT;
778 mtx_unlock(&tp->tap_mtx);
779 error = tsleep(tp,PCATCH|(PZERO+1),"taprd",0);
785 /* feed packet to bpf */
788 /* xfer packet to user space */
789 while ((m != NULL) && (uio->uio_resid > 0) && (error == 0)) {
790 len = min(uio->uio_resid, m->m_len);
794 error = uiomove(mtod(m, void *), len, uio);
799 TAPDEBUG("%s dropping mbuf, minor = %#x\n", ifp->if_xname,
811 * the cdevsw write interface - an atomic write is a packet - or else!
814 tapwrite(struct cdev *dev, struct uio *uio, int flag)
816 struct tap_softc *tp = dev->si_drv1;
817 struct ifnet *ifp = tp->tap_ifp;
820 TAPDEBUG("%s writting, minor = %#x\n",
821 ifp->if_xname, minor(dev));
823 if (uio->uio_resid == 0)
826 if ((uio->uio_resid < 0) || (uio->uio_resid > TAPMRU)) {
827 TAPDEBUG("%s invalid packet len = %d, minor = %#x\n",
828 ifp->if_xname, uio->uio_resid, minor(dev));
833 if ((m = m_uiotombuf(uio, M_DONTWAIT, 0, ETHER_ALIGN,
834 M_PKTHDR)) == NULL) {
839 m->m_pkthdr.rcvif = ifp;
841 /* Pass packet up to parent. */
842 (*ifp->if_input)(ifp, m);
843 ifp->if_ipackets ++; /* ibytes are counted in parent */
852 * the poll interface, this is only useful on reads
853 * really. the write detect always returns true, write never blocks
854 * anyway, it either accepts the packet or drops it
857 tappoll(struct cdev *dev, int events, struct thread *td)
859 struct tap_softc *tp = dev->si_drv1;
860 struct ifnet *ifp = tp->tap_ifp;
863 TAPDEBUG("%s polling, minor = %#x\n",
864 ifp->if_xname, minor(dev));
867 if (events & (POLLIN | POLLRDNORM)) {
868 if (ifp->if_snd.ifq_len > 0) {
869 TAPDEBUG("%s have data in queue. len = %d, " \
870 "minor = %#x\n", ifp->if_xname,
871 ifp->if_snd.ifq_len, minor(dev));
873 revents |= (events & (POLLIN | POLLRDNORM));
875 TAPDEBUG("%s waiting for data, minor = %#x\n",
876 ifp->if_xname, minor(dev));
878 selrecord(td, &tp->tap_rsel);
882 if (events & (POLLOUT | POLLWRNORM))
883 revents |= (events & (POLLOUT | POLLWRNORM));
893 * support for kevent() system call
896 tapkqfilter(struct cdev *dev, struct knote *kn)
899 struct tap_softc *tp = dev->si_drv1;
900 struct ifnet *ifp = tp->tap_ifp;
903 switch (kn->kn_filter) {
905 TAPDEBUG("%s kqfilter: EVFILT_READ, minor = %#x\n",
906 ifp->if_xname, minor(dev));
907 kn->kn_fop = &tap_read_filterops;
911 TAPDEBUG("%s kqfilter: EVFILT_WRITE, minor = %#x\n",
912 ifp->if_xname, minor(dev));
913 kn->kn_fop = &tap_write_filterops;
917 TAPDEBUG("%s kqfilter: invalid filter, minor = %#x\n",
918 ifp->if_xname, minor(dev));
925 kn->kn_hook = (caddr_t) dev;
926 knlist_add(&tp->tap_rsel.si_note, kn, 0);
935 * Return true if there is data in the interface queue
938 tapkqread(struct knote *kn, long hint)
941 struct cdev *dev = (struct cdev *)(kn->kn_hook);
942 struct tap_softc *tp = dev->si_drv1;
943 struct ifnet *ifp = tp->tap_ifp;
946 if ((kn->kn_data = ifp->if_snd.ifq_len) > 0) {
947 TAPDEBUG("%s have data in queue. len = %d, minor = %#x\n",
948 ifp->if_xname, ifp->if_snd.ifq_len, minor(dev));
951 TAPDEBUG("%s waiting for data, minor = %#x\n",
952 ifp->if_xname, minor(dev));
964 * Always can write. Return the MTU in kn->data
967 tapkqwrite(struct knote *kn, long hint)
970 struct tap_softc *tp = ((struct cdev *) kn->kn_hook)->si_drv1;
971 struct ifnet *ifp = tp->tap_ifp;
974 kn->kn_data = ifp->if_mtu;
982 tapkqdetach(struct knote *kn)
984 struct tap_softc *tp = ((struct cdev *) kn->kn_hook)->si_drv1;
986 knlist_remove(&tp->tap_rsel.si_note, kn, 0);