あなたの知らないネットワークプログラミングの世界

1,756 views
1,658 views

Published on

第二回カーネル・VM探検隊。2009-11-05

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,756
On SlideShare
0
From Embeds
0
Number of Embeds
32
Actions
Shares
0
Downloads
16
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

あなたの知らないネットワークプログラミングの世界

  1. 1. oraccha Plan9 http://d.hatena.ne.jp/oraccha/ 2009 11 5 VM Thursday, November 5, 2009
  2. 2. Plan 9 • Plan 9 ... • UNIX V1 • xv6 • V7/x86 • 2.11BSD • X Window System Thursday, November 5, 2009
  3. 3. Plan 9 4th International Workshop on Plan 9 ... Thursday, November 5, 2009
  4. 4. • Plan 9 • BSD dial(2) • acid truss Thursday, November 5, 2009
  5. 5. Plan 9 • • 9P • Thursday, November 5, 2009
  6. 6. • • open-read-write-close Thursday, November 5, 2009
  7. 7. ... UNIX UNIX • • UCB • GUI • X MIT Thursday, November 5, 2009
  8. 8. API • open-read-write-close • BSD • Thursday, November 5, 2009
  9. 9. /net • • • /net/ether0 • /net/^(arp icmp udp tcp) • /net/^(cs dns) Thursday, November 5, 2009
  10. 10. /net/tcp • /net/tcp/N • ctl • data • /net/tcp/clone % lc /net/tcp 0 1 10 ... clone stats % lc /net/tcp/0 ctl data err listen local remote status Thursday, November 5, 2009
  11. 11. echo client terminal 1: % cat /net/tcp/clone open(“/net/tcp/clone”) 5 open(“/net/tcp/*/ctl”) % cat > /net/tcp/clone connect 204.178.31.2!7 terminal 2: % cat /net/tcp/5/data & % echo hoge > /net/tcp/5/data echo Thursday, November 5, 2009
  12. 12. telnet client clonefile=/net/tcp/clone if(! ~ $#* 2) { echo Usage: telnet ip port >[1=2] exit usage } <[4] $clonefile { netdir=`{basename -d $clonefile} ^ / ^ `{cat /fd/4} echo connect $1!$2 >$netdir/ctl || exit 'cannot connect' cat $netdir/data & cat >$netdir/data } Thursday, November 5, 2009
  13. 13. /net/cs • • clone IP % ndb/csquery > tcp!www.bell-labs.com!http /net/tcp/clone 135.245.1.14!80 Thursday, November 5, 2009
  14. 14. • % srv tcp!plan9.bell-labs.com!http foo post... % netstat -n tcp 29 oraccha Established 58069 80 204.178.31.2 % echo GET /plan9/index.html >>/srv/foo % cat /srv/foo <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> : % rm /srv/foo Thursday, November 5, 2009
  15. 15. echo int fd, n; char *name; name = netmkaddr(“plan9.bell-labs.com”, “tcp”, “echo”); “204.178.31.2!echo fd = dial(name, 0, 0, 0); : n = write(fd, buf, sizeof(buf)); read(1, buf, n); Thursday, November 5, 2009
  16. 16. echo int acfd, lcfd, dfd, n; char adir[40], ldir[40] /net/tcp/5 acfd = announce("tcp!*!7", adir); for (;;) { /net/tcp/6 lcfd = listen(adir, ldir); switch (fork()) { UNIX case 0: dfd = accept(lcfd, ldir); while ((n = read(dfd, buf, sizeof(buf))) > 0) write(dfd, buf, n); exits(0); } } Thursday, November 5, 2009
  17. 17. BSD Plan 9 BSD socket dial active open fd socket announce passive open fd dial connect active open - bind announce listen listen/accept accept reject close - shutdown Thursday, November 5, 2009
  18. 18. • dial(2) • /sys/src/libc/9sys/dial.c • announce(2), listen(2), accept(2), reject(2) • /sys/src/libc/9sys/announce.c • netmkaddr(2) • /sys/src/libc/port/netmkaddr.c • /net/cs • /sys/src/cmd/ndb/cs.c Thursday, November 5, 2009
  19. 19. acid truss (strace) % acid -l truss a.out a.out:386 plan 9 executable /sys/lib/acid/port /sys/lib/acid/truss /sys/lib/acid/386 acid: new() acid: truss() : Thursday, November 5, 2009
  20. 20. echo truss / # dial(2) open("/net/cs", 2) # open connection server return value: 3 pwrite(3, "tcp!192.168.0.1!8007", 20, -1) # translate the address return value: 20 seek(0x00013e30, 3, 0, 0) return value: 0 pread(3, 0x7fffec00, 127, -1) return value: 31 data: "/net/tcp/clone 192.168.0.1!8007" Thursday, November 5, 2009
  21. 21. echo truss / open("/net/tcp/clone", 2) # open clone file return value: 4 pread(4, 0x7fffe7d0, 255, -1) # get directory name return value: 2 data: "33" # connect(2) pwrite(4, "connect 192.168.0.1!8007", 24, -1) # connect return value: 24 open("/net/tcp/33/data", 2) # open data connection return value: 5 close(4) # close clone file return value: 0 close(3) # close connection server return value: 0 Thursday, November 5, 2009
  22. 22. echo truss / # echo pread(0, 0x00014aa8, 4096, -1) glenda # input “glenda” from stdin return value: 7 data: "glenda " pwrite(5, "glenda ", 8, -1) return value: 8 pread(5, 0x7fffee5c, 256, -1) return value: 8 data: "glenda " pwrite(1, "glenda ", 8, -1) glenda # output “glenda” to stdout return value: 8 Thursday, November 5, 2009
  23. 23. echod truss / # announce(2) open("/net/cs", 2) # open connection server return value: 3 pwrite(3, "tcp!*!8007", 10, -1) # translate the address return value: 10 seek(0x00007a94, 3, 0, 0) return value: 0 pread(3, 0x7fffe8b4, 255, -1) return value: 19 data: "/net/tcp/clone 8007" close(3) # close connection server return value: 0 Thursday, November 5, 2009
  24. 24. echod truss / open("/net/tcp/clone", 2) # open clone file return value: 3 pread(3, 0x7fffece9, 246, -1) # get directory name return value: 2 data: "29" pwrite(3, "announce 8007", 13, -1) # announce service return value: 13 # listen(2) open("/net/tcp/29/listen", 2) # open listen file return value: 4 pread(4, 0x7fffece9, 246, -1) # get directory name return value: 2 data: "34" Thursday, November 5, 2009
  25. 25. echod truss / # accept(2) pwrite(4, "accept 34", 9, -1) # accept a call return value: -1 # (ignore return value) open("/net/tcp/34/data", 2) # open data file return value: 5 # echod pread(5, 0x7fffee04, 256, -1) return value: 8 data: "glenda " pwrite(5, "glenda ", 8, -1) return value: 8 Thursday, November 5, 2009
  26. 26. • man dial(2) • Pegasus by • http://plan9.aichi-u.ac.jp/pegasus/ Thursday, November 5, 2009
  27. 27. TODO • • TCP/IP • TCP: 3200 • UDP: 620 • Thursday, November 5, 2009
  28. 28. • • open-close-read-write • Plan 9 • Thursday, November 5, 2009
  29. 29. Plan9 http://d.hatena.ne.jp/oraccha/ Thursday, November 5, 2009

×