]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/cwfs/net.c
webfs(4): document -d and -D flags
[plan9front.git] / sys / src / cmd / cwfs / net.c
1 /* network i/o */
2
3 #include "all.h"
4 #include "io.h"
5
6 /*
7  * the kernel file server read packets directly from
8  * its ethernet(s) and did all the protocol processing.
9  * if the incoming packets were 9p (over il/ip), they
10  * were queued for the server processes to operate upon.
11  *
12  * in user mode, we have one process per incoming connection
13  * instead, and those processes get just the data, minus
14  * tcp and ip headers, so they just see a stream of 9p messages,
15  * which they then queue for the server processes.
16  *
17  * there used to be more queueing (in the kernel), with separate
18  * processes for ethernet input, il input, 9p processing, il output
19  * and ethernet output, and queues connecting them.  we now let
20  * the kernel's network queues, protocol stacks and processes do
21  * much of this work.
22  *
23  * partly as a result of this, we can now process 9p messages
24  * transported via tcp, exploit multiple x86 processors, and
25  * were able to shed 70% of the file server's source, by line count.
26  *
27  * the upshot is that Ether (now Network) is no longer a perfect fit for
28  * the way network i/o is done now.  the notion of `connection'
29  * is being introduced to complement it.
30  */
31
32 typedef struct Network Network;
33
34 /* a network, not necessarily an ethernet */
35 struct Network {
36         int     ctlrno;
37         char    name[NAMELEN];
38
39         char    *dialstr;
40         char    anndir[40];
41         char    lisdir[40];
42         int     annfd;                  /* fd from announce */
43 };
44
45 static Network netif[Maxnets];
46
47 char *annstrs[Maxnets];
48
49 static void
50 neti(void *v)
51 {
52         int lisfd, accfd;
53         NetConnInfo *nci;
54         Network *net;
55
56         net = v;
57         for(;;) {
58                 if((lisfd = listen(net->anndir, net->lisdir)) < 0){
59                         fprint(2, "%s: listen %s failed: %r\n", argv0, net->anndir);
60                         break;
61                 }
62                 /* got new call on lisfd */
63                 if((accfd = accept(lisfd, net->lisdir)) < 0){
64                         fprint(2, "%s: accept %d (from %s) failed: %r\n", argv0, lisfd, net->lisdir);
65                         close(lisfd);
66                         continue;
67                 }
68                 nci = getnetconninfo(net->lisdir, accfd);
69                 if(srvchan(accfd, nci->raddr) == nil){
70                         fprint(2, "%s: srvchan failed for: %s\n", argv0, nci->raddr);
71                         close(accfd);
72                 }
73                 freenetconninfo(nci);
74         }
75 }
76
77 void
78 netstart(void)
79 {
80         Network *net;
81
82         for(net = &netif[0]; net < &netif[Maxnets]; net++){
83                 if(net->dialstr == nil || *net->anndir == 0)
84                         continue;
85                 sprint(net->name, "net%di", net->ctlrno);
86                 newproc(neti, net, net->name);
87         }
88 }
89
90 void
91 netinit(void)
92 {
93         Network *net;
94
95         for (net = netif; net < netif + Maxnets; net++) {
96                 net->dialstr = annstrs[net - netif];
97                 if(net->dialstr == nil)
98                         continue;
99                 if((net->annfd = announce(net->dialstr, net->anndir)) < 0){
100                         fprint(2, "can't announce %s: %r", net->dialstr);
101                         net->dialstr = nil;
102                         continue;
103                 }
104                 if(chatty)
105                         print("netinit: announced on %s\n", net->dialstr);
106         }
107 }