Message-Passing Network Daemons
Total Page:16
File Type:pdf, Size:1020Kb
Metanet: Message-Passing Network Daemons Erik Walthinsen [email protected], http://www.omegacs.net/˜omega/ Abstract ficult to accomplish the task at hand, or more likely they are simply too big to fit on the MetaNet is a message-passing architecture de- target device. The platform example used in signed for the construction of network services this paper is that of an intelligent wireless daemons. Services are implemented as a series access point (AP) running Linux. The M1 of mailboxes with attached functions to pro- from Musenki [Musenki] is just such an access vide the functionality. The mailbox namespace point, consisting of a Motorola MPC8241 em- is global across all services, allowing new dae- bedded PPC processor, 32MB of RAM, 8MB mons to hook into existing daemons to mod- of flash, a 10/100 NIC, and a MiniPCI slot for ify their behavior. A simple example is a stock a wireless card. It runs Linux natively and must DHCP daemon hooked by an external applica- be able to provide all the normal network ser- tion that does an LDAP lookup for a machine’s vices, as well as be useful to the PersonalTelco IP before falling back to the normal DHCP al- Project [PTP] in its city-wide free networking location scheme. This paper covers the archi- projects. This drives some of the more inter- tecture of the MetaNet system, and uses the ex- esting requirements, pushing well beyond the ample of a Captive Portal as used for public boundaries of current software. wireless network control to show how multi- MetaNet is an attempt at creating an infras- ple services can be quite easily tied together to tructure that enables these services to be not provide more complex services. Other possible only small, but capable of extremely complex projects using MetaNet will also be explored. interactions. MetaNet itself is only an archi- tectural design, not a specific implementation. The reference implementation is currently (as 1 Introduction of this writing) written in Perl for convenience, but could be and will be implemented in other Network services on Unix machines are pro- languages such as C and Python. More ad- vided today by separate daemons designed for vanced features ensure that these languages can each protocol and service. Each has its own in- be mixed freely in larger systems, allowing ternal structure, configuration files, behaviors, high-speed services to be written in C and other history, and so on. This works well in most services or glue code to be written in a scripted environments because each service is designed language. to be completely standalone, as this is one of the driving principles behind Unix: “Do one thing, and do it well.” For the most part, each 2 Unusual Requirements of these daemons does indeed do its job rea- sonably well. The PersonalTelco Project (PTP) has several (4 Unfortunately, there are situations where this as of this writing, more on the way) open, pub- myriad of separate daemons can make it dif- lic access points covering several very public Ottawa Linux Symposium 2002 557 locations in Portland, OR. The most visible of creet daemons and why it would be nearly im- these is the node at Pioneer Courthouse Square, possible, a simpler example will suffice to ex- aka “Portland’s Living Room”, in the center of plain the basic MetaNet concepts. downtown. A wireless AP covers the Square On many large networks, an LDAP database is and is connected to the Internet by redundant used to hold information about each machine T-1’s that are otherwise heavily underutilized and user. If this database includes the MAC by the company donating the space and band- address of a machine and the intended IP ad- width. Because the signal is unencrypted and dress, this information must be made available usable by anyone with a laptop and a wireless to the DHCP server. card, some steps are necessary in order to keep With ISC dhcpd [ISC] as shipped with almost usage under control, and limit or avoid liability. all Linux distributions, this would have to be The solution used is called a “Captive Por- accomplished by extracting the relevant pieces tal.” The idea behind such a portal is that new from the LDAP database and constructing a clients on the wireless network are by default dhcpd.conf. This would have to be done ev- completely firewalled off from the Internet. In ery time the LDAP database changes, must be order for the user to gain access to the net- pushed to each DHCP server, and dhcpd has work they must log in after agreeing to a us- to be restarted. On a large network this could age policy, etc. Custom client login software is become quite a hassle to manage. unworkable because it would have to be dis- tributed to clients and installed, which most savvy users wouldn’t even consider. Instead, 4 The MetaNet Approach the portal uses software the user already has: a browser. Linux Netfilter [Netfilter] transpar- MetaNet is designed to split the implemen- ent redirects are used to shuttle all HTTP con- tation of network services into discreet com- nections to a web server contained in the por- ponents which communicate by passing mes- tal software itself. When the user successfully sages. The degree to which the software is split logs in, the firewall is modified to allow that into pieces determines the degree to which it client access to the Internet. can be integrated with other services. Once the client is associated and logged into The fundamental entity is a “message”, which the portal, there are several other aspects that is simply a list of tag/type/value tuples sent to a have to be dealt with. The first is the fact that specific “mailbox”. All control and data trans- a spammer could trivially send mass quantities fer takes place via these messages. Objects that of email through such a wide-open connection, encompass various services such as sockets or and could do so untraceably. Another is mak- web servers are simply a set of mailboxes with ing sure that no single client abuses the up- which other objects interact. stream connection and effectively locks other The mailbox names are strings that use clients off the network. Statistics logging and a filesystem-style path syntax, allowing “Extrusion Detection” are also critical compo- for an effectively unlimited namespace if nents that have to be built into such a system. used properly. Common messages include "/system/socket/new" to create a new socket, or "/httpd/request" when the 3 An Example web server gets a remote request. Most such mailbox names are indeed derived from the Rather than explaining how one might imple- name of the object that created them, such as ment a complete Captive Portal with fully dis- in the previous example where the object is Ottawa Linux Symposium 2002 558 simply named "/httpd". and general program style used to construct the In order to capture messages sent to a mail- MetaNet library. The current Perl prototype box, a “listener” is attached. This is a function does not yet use messages to indicate readable pointer (or reference, in Perl), coupled with file descriptors or timeouts, though there is no another list of tuples to allow the specific in- technical reason this cannot be changed to a stance of that function pointer to be uniquely more consistent style. identified. (Mailboxes themselves in fact have tuples associated with them for the same rea- son.) Each mailbox maintains an ordered list 6 DHCP and LDAP of these listeners, so that when a message is sent to the mailbox, these listeners are called In our example scenario, the DHCP server in order. As a special case, a listener can re- would be written in such a way as to ex- turn an error code that indicates that no more pose many mailboxes through which its inter- listeners should be called. nal control passes. Upon creation, it would in- There are two conceptually different kinds of stantiate a socket to listen for requests. When mailboxes, with no actual technical difference a request packet arrives, the socket will send between them. The difference lies in who is a "read" message for the server to pick up listening and who is sending the messages. In and translate from the packed DHCP format the case of a socket, the "read" message is to a more readable set of tuples, which is then sent by the socket code itself, and the nomi- sent as a DHCP-specific message. The DHCP nal owner of the socket supplies a listener to server then must maintain the whole of the catch the data received on the socket. The DHCP state machine internally, likely using "write" request on the other hand works the the machine’s MAC address (“chaddr” in dhcp) other way around, with the owner sending the as key. message and the socket’s listener responsible The state machine will at some point need to for write()ing the data to the socket. In some find an IP address for the host. Normally cases both the object and external entities can this is done by sending a message to a mail- provide listeners, for instance as a means of box that might be named "lookup" or similar, keeping track of what an object is doing or be- which another part of the stock DHCP server ing told to do. would be listening to. This code would per- form the usual lookup of a free IP address in the pool, or find an address recently associated 5 The Main Loop with that MAC address.