]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ux/net.cpp
Update
[l4.git] / kernel / fiasco / src / kern / ux / net.cpp
1 //
2 // Network handling for Fiasco-UX
3 //
4
5 INTERFACE:
6
7 class Net
8 {
9 public:
10   static void init();
11   static void enable();
12
13 private:
14   static int tunfd;
15
16   static void bootstrap();
17 };
18
19 // ------------------------------------------------------------------------
20 IMPLEMENTATION:
21
22 #include <cstdlib>
23 #include <cstdio>
24 #include <unistd.h>
25 #include <fcntl.h>
26 #include "boot_info.h"
27 #include "initcalls.h"
28 #include "irq_chip.h"
29 #include "kmem.h"
30 #include "irq_chip_ux.h"
31 #include "warn.h"
32
33 int Net::tunfd;
34
35 IMPLEMENT FIASCO_INIT
36 void
37 Net::bootstrap()
38 {
39   char s_net_fd[3];
40
41   snprintf (s_net_fd,  sizeof (s_net_fd),  "%u",  tunfd);
42
43   execl (Boot_info::net_program(), Boot_info::net_program(),
44          "-t", s_net_fd, NULL);
45 }
46
47 IMPLEMENT FIASCO_INIT
48 void
49 Net::init()
50 {
51   // Check if frame buffer is available
52   if (!Boot_info::net())
53     return;
54
55   if ((tunfd = open("/dev/net/tun", O_RDWR)) < 0)
56     {
57       perror("open of /dev/net/tun");
58       exit(1);
59     }
60
61   // Setup virtual interrupt
62   auto chip = Irq_chip_ux::main;
63   auto const irq = Irq_chip_ux::Irq_net;
64   if (!chip->setup_irq_prov(irq, Boot_info::net_program(), bootstrap))
65     {
66       puts("Problems setting up network interrupt!");
67       exit(1);
68     }
69
70   Kip::k()->vhw()->set_desc(Vhw_entry::TYPE_NET,
71                             0, 0, irq, chip->pid_for_irq_prov(irq), tunfd);
72
73   printf("Starting Network.\n\n");
74 }