hubertf's NetBSD Blog
Send interesting links to hubert at feyrer dot de!
 
[20050801] Multiplexing TCP services: inetd's tcpmux (Updated)
Have you ever used inetd's built-in tcpmux service? Neither have I, but after someone asked about it on #NetBSD today, I thought to give it a try. After not understanding the manpage on first read, it seems it's a re-invention of rpcbind (or vice versa), where you can create a TCP connection to the tcpmux port (1/tcp), and ask for a connection to a service to which you get connected then, by only knowing a service name, no port number needed.

Here's an example:

 (a) --> miyu# egrep '^(tcpmux|ftp)' /etc/inetd.conf 
         ftp             stream  tcp     nowait  root    /usr/libexec/ftpd       ftpd -ll
         tcpmux          stream  tcp     nowait  root    internal
 (b) --> miyu# telnet localhost 1
         Trying 127.0.0.1...
         Connected to localhost.
         Escape character is '^]'.
 (c) --> ftp
 (d) --> -Service not available
         Connection closed by foreign host.
 (e) --> miyu# egrep ^ftp /etc/inetd.conf | sed 's,^,tcpmux/,' >>/etc/inetd.conf
 (f) --> miyu# egrep '^ftp' /etc/inetd.conf
         ftp             stream  tcp     nowait  root    /usr/libexec/ftpd       ftpd -ll
         tcpmux          stream  tcp     nowait  root    internal
         tcpmux/ftp      stream  tcp     nowait  root    /usr/libexec/ftpd       ftpd -ll
         miyu# alias hup 
         kill -1 `cat /var/run/!*.pid`
 (g) --> miyu# hup inetd
 (h) --> miyu# telnet localhost 1
         Trying 127.0.0.1...
         Connected to localhost.
         Escape character is '^]'.
 (i) --> ftp
 (j) --> 220-
         220 localhost FTP server (NetBSD-ftpd 20050303) ready.
 (k) --> ^]
         telnet> quit
         Connection closed.
         miyu# 
The example first checks that the FTP and TCPMUX service are enabled in inetd.conf (a), then connects to the local tcpmux port (b) to ask for a connection to the "ftp" service (c), which is not available (d). Now after reading the inetd(8) manpage five times, duplicate the "ftp" line and prefix it with "tcpmux/" (e), and check that it got added to inetd.conf (f). Make sure that inetd reads in the changed config file (g). When connecting now (h) and asking for the "ftp" service (i), the ftp daemon is started and prints its banner (j).

As I don't really feel like speaking FTP without a client, I disconnect (k) and exit telnet.

So, the tcpmux service seems quite a nice tool which could be used to obsolete assigning ports in favour of service names. The problem is that no TCP service that I've stumbled across ever uses this nice mechanism. Even more strange, I wonder why things like rpcbind/portmap were invented in the presence of that serivce (and I guess that tcpmux does predate rpcbind etc.).

To play a bit more, I built myself a "cookie" service, adding this to /etc/inetd.conf:

tcpmux/cookie   stream  tcp     nowait  root    /usr/games/fortune fortune
Now I can run:
      miyu# echo cookie | nc localhost 1
      'Home, Sweet Home' must surely have been written by a bachelor.
      miyu# 

Who needs port numbers when you can request a service like this easily. :-) After reading RFC 1078, I even found that the protocol could safe one portscanning a machine to find out the services it runs:

      miyu# echo HELP | nc localhost 1
      +Available services:
      help
      cookie
      ftp
      miyu# 

And for the problem of having multiple versions of the same service running (which rpcbind addresses), RFC 1078 has a suggestion, too: ``Multiple versions of a protocol can suffix the service name with a protocol version number. ''. Easy, huh?

Looking into portmap and friends, Appendix A of RFC 1047 says that ``The port mapper program maps RPC program and version numbers to transport-specific port numbers. This program makes dynamic binding of remote programs possible.''. I.e. reasons for existance of rpcbind etc. are that that rpcbind does which are not easily achievable with the inetd/tcpmux combination: dynamic registration of services, transport over UDP and handling of broadcast requests.


P.S.: Try running fortune(6) without argv[0] being set. :-)


Update: Aparently the tcpmux service is actualy being used by Irix 6.5. Martin Neitzel sent me the inetd.conf of such a machine:

 % grep tcpmux irix65_inetd.conf
 tcpmux  stream  tcp     nowait  root    internal
 tcpmux/sgi_scanner stream tcp nowait root   ?/usr/lib/scan/net/scannerd scannerd
 tcpmux/sgi_printer stream tcp nowait root   ?/usr/lib/print/printerd printerd
 tcpmux/sgi_sysadm stream tcp nowait root   ?/usr/sysadm/bin/sysadmd sysadmd
 tcpmux/sgi_dmusrcmd stream tcp nowait root ?/usr/etc/dmusrcmd /usr/etc/dmusrcmd 


[Tags: , ]


Tags: , 2bsd, 3com, 501c3, 64bit, acl, acls, acm, acorn, acpi, acpitz, adobe, Advocacy, advocacy, advogato, aes, afs, aiglx, aio, airport, alereon, alex, alix, alpha, altq, am64t, amazon, amd64, anatomy, ansible, apache, apm, apple, arkeia, arla, arm, art, Article, Articles, ascii, asiabsdcon, aslr, asterisk, asus, atf, ath, atheros, atmel, audio, audiocodes, autoconf, avocent, avr32, aws, axigen, azure, backup, balloon, banners, basename, bash, bc, beaglebone, benchmark, bigip, bind, blackmouse, bldgblog, blog, blogs, blosxom, bluetooth, board, bonjour, books, boot, boot-z, bootprops, bozohttpd, bs2000, bsd, bsdca, bsdcan, bsdcertification, bsdcg, bsdforen, bsdfreak, bsdmac, bsdmagazine, bsdnexus, bsdnow, bsdstats, bsdtalk, bsdtracker, bug, build.sh, busybox, buttons, bzip, c-jump, c99, cafepress, calendar, callweaver, camera, can, candy, capabilities, card, carp, cars, cauldron, ccc, ccd, cd, cddl, cdrom, cdrtools, cebit, centrino, cephes, cert, certification, cfs, cgd, cgf, checkpointing, china, christos, cisco, cloud, clt, cobalt, coccinelle, codian, colossus, common-criteria, community, compat, compiz, compsci, concept04, config, console, contest, copyright, core, cortina, coverity, cpu, cradlepoint, cray, crosscompile, crunchgen, cryptography, csh, cu, cuneiform, curses, curtain, cuwin, cvs, cvs-digest, cvsup, cygwin, daemon, daemonforums, daimer, danger, darwin, data, date, dd, debian, debugging, dell, desktop, devd, devfs, devotionalia, df, dfd_keeper, dhcp, dhcpcd, dhcpd, dhs, diezeit, digest, digests, dilbert, dirhash, disklabel, distcc, dmesg, Docs, Documentation, donations, draco, dracopkg, dragonflybsd, dreamcast, dri, driver, drivers, drm, dsl, dst, dtrace, dvb, ec2, eclipse, eeepc, eeepca, ehci, ehsm, eifel, elf, em64t, Embedded, embedded, emips, emulate, encoding, envsys, eol, espresso, etcupdate, etherip, euca2ools, eucalyptus, eurobsdcon, eurosys, Events, exascale, ext3, f5, facebook, falken, fan, faq, fatbinary, features, fefe, ffs, filesystem, fileysstem, firefox, firewire, fireworks, flag, flash, flashsucks, flickr, flyer, fmslabs, force10, fortunes, fosdem, fpga, freebsd, freedarwin, freescale, freex, freshbsd, friendlyAam, friendlyarm, fritzbox, froscamp, fsck, fss, fstat, ftp, ftpd, fujitsu, fun, fundraising, funds, funny, fuse, fusion, g4u, g5, galaxy, games, gcc, gdb, gentoo, geode, getty, gimstix, git, gnome, google, google-soc, googlecomputeengine, gpio, gpl, gprs, gracetech, gre, groff, groupwise, growfs, grub, gumstix, guug, gzip, hackathon, hackbench, hal, hanoi, happabsd, hardware, Hardware, haze, hdaudio, heat, heimdal, hf6to4, hfblog, hfs, history, hosting, hotplug, hp, hp700, hpcarm, hpcsh, hpux, html, httpd, hubertf, hurd, i18n, i386, i386pkg, ia64, ian, ibm, ids, ieee, ifwatchd, igd, iij, image, images, imx233, imx7, information, init, initrd, install, intel, interix, internet2, interview, interviews, io, ioccc, iostat, ipbt, ipfilter, ipmi, ipplug, ipsec, ipv6, irbsd, irc, irix, iscsi, isdn, iso, isp, itojun, jail, jails, japanese, java, javascript, jetson, jibbed, jihbed, jobs, jokes, journaling, kame, kauth, kde, kerberos, kergis, kernel, keyboardcolemak, kirkwood, kitt, kmod, kolab, kvm, kylin, l10n, landisk, laptop, laptops, law, ld.so, ldap, lehmanns, lenovo, lfs, libc, license, licensing, linkedin, links, linksys, linux, linuxtag, live-cd, lkm, localtime, locate.updatedb, logfile, logging, logo, logos, lom, lte, lvm, m68k, macmini, macppc, macromedia, magicmouse, mahesha, mail, makefs, malo, mame, manpages, marvell, matlab, maus, max3232, mbr95, mbuf, mca, mdns, mediant, mediapack, meetbsd, mercedesbenz, mercurial, mesh, meshcube, mfs, mhonarc, microkernel, microsoft, midi, mini2440, miniroot, minix, mips, mirbsd, missile, mit, mixer, mobile-ip, modula3, modules, money, mouse, mp3, mpls, mprotect, mtftp, mult, multics, multilib, multimedia, music, mysql, named, nas, nasa, nat, ncode, ndis, nec, nemo, neo1973, netbook, netboot, netbsd, netbsd.se, nethack, nethence, netksb, netstat, netwalker, networking, neutrino, nforce, nfs, nis, npf, npwr, nroff, nslu2, nspluginwrapper, ntfs-3f, ntp, nullfs, numa, nvi, nvidia, nycbsdcon, office, ofppc, ohloh, olimex, olinuxino, olpc, onetbsd, openat, openbgpd, openblocks, openbsd, opencrypto, opendarwin, opengrok, openmoko, openoffice, openpam, openrisk, opensolaris, openssl, or1k, oracle, oreilly, oscon, osf1, osjb, paas, packages, pad, pae, pam, pan, panasonic, parallels, pascal, patch, patents, pax, paypal, pc532, pc98, pcc, pci, pdf, pegasos, penguin, performance, pexpect, pf, pfsync, pgx32, php, pie, pike, pinderkent, pkg_install, pkg_select, pkgin, pkglint, pkgmanager, pkgsrc, pkgsrc.se, pkgsrcCon, pkgsrccon, Platforms, plathome, pleiades, pocketsan, podcast, pofacs, politics, polls, polybsd, portability, posix, postinstall, power3, powernow, powerpc, powerpf, pppoe, precedence, preemption, prep, presentations, prezi, Products, products, proplib, protectdrive, proxy, ps, ps3, psp, psrset, pthread, ptp, ptyfs, Publications, puffs, puredarwin, pxe, qemu, qnx, qos, qt, quality-management, quine, quote, quotes, r-project, ra5370, radio, radiotap, raid, raidframe, rants, raptor, raq, raspberrypi, rc.d, readahead, realtime, record, refuse, reiserfs, Release, Releases, releases, releng, reports, resize, restore, ricoh, rijndael, rip, riscos, rng, roadmap, robopkg, robot, robots, roff, rootserver, rotfl, rox, rs323, rs6k, rss, ruby, rump, rzip, sa, safenet, san, savin, sbsd, scampi, scheduler, scheduling, schmonz, sco, screen, script, sdf, sdtemp, secmodel, Security, security, sed, segvguard, seil, sendmail, serial, serveraptor, sfu, sge, sgi, sgimips, sh, sha2, shark, sharp, shisa, shutdown, sidekick, size, slackware, slashdot, slides, slit, smbus, smp, sockstat, soekris, softdep, softlayer, software, solaris, sony, sound, source, source-changes, spanish, sparc, sparc64, spider, spreadshirt, spz, squid, ssh, sshfs, ssp, statistics, stereostream, stickers, stty, studybsd, subfile, sudbury, sudo, summit, sun, sun2, sun3, sunfire, sunpci, support, sus, suse, sushi, susv3, svn, swcrypto, symlinks, sysbench, sysctl, sysinst, sysjail, syslog, syspkg, systat, systrace, sysupdate, t-shirt, tabs, talks, tanenbaum, tape, tcp, tcp/ip, tcpdrop, tcpmux, tcsh, teamasa, tegra, teredo, termcap, terminfo, testdrive, testing, tetris, tex, TeXlive, thecus, theopengroup, thin-client, thinkgeek, thorpej, threads, time, time_t, timecounters, tip, tk1, tme, tmp, tmpfs, tnf, toaster, todo, toolchain, top, torvalds, toshiba, touchpanel, training, translation, tso, tty, ttyrec, tulip, tun, tuning, uboot, ucom, udf, ufs, ukfs, ums, unetbootin, unicos, unix, updating, upnp, uptime, usb, usenix, useradd, userconf, userfriendly, usermode, usl, utc, utf8, uucp, uvc, uvm, valgrind, vax, vcfe, vcr, veriexec, vesa, video, videos, virtex, virtualization, vm, vmware, vnd, vobb, voip, voltalinux, vpn, vpnc, vulab, w-zero3, wallpaper, wapbl, wargames, wasabi, webcam, webfwlog, wedges, wgt624v3, wiki, willcom, wimax, window, windows, winmodem, wireless, wizd, wlan, wordle, wpa, wscons, wstablet, X, x.org, x11, x2apic, xbox, xcast, xen, Xen, xfree, xfs, xgalaxy, xilinx, xkcd, xlockmore, xmms, xmp, xorg, xscale, youos, youtube, zaurus, zdump, zfs, zlib

'nuff. Grab the RSS-feed, index, or go back to my regular NetBSD page

Disclaimer: All opinion expressed here is purely my own. No responsibility is taken for anything.

Access count: 23625081
Copyright (c) Hubert Feyrer