Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
ある日、突然ホスト名が “MacBookPro” になった話
Search
Yoshimasa Niwa
October 30, 2024
0
250
ある日、突然ホスト名が “MacBookPro” になった話
ある日、突然ホスト名が “MacBookPro” になった話
Yoshimasa Niwa
October 30, 2024
Tweet
Share
More Decks by Yoshimasa Niwa
See All by Yoshimasa Niwa
SwiftUI API Design Lessons
niw
2
360
TextKit 2 時代の iOS のキーボードとテキスト入力と表示のすべて
niw
6
4.2k
Xcode が遅い! とにかく遅い!! 遅い Xcode をなんとかする方法
niw
1
8.4k
実践 iOS オープンソースプロジェクトの始め方
niw
6
3.4k
iOS のキーボードと文字入力のすべて
niw
14
3.2k
Getting started with making macOS utility app using private APIs
niw
3
2.6k
アプリの国際化の舞台裏
niw
11
7.6k
Lessons Learned
niw
6
5.1k
Getting Started with Scalding, Storm and Summingbird
niw
9
2.9k
Featured
See All Featured
Making Projects Easy
brettharned
116
6.2k
Why You Should Never Use an ORM
jnunemaker
PRO
56
9.4k
How to Think Like a Performance Engineer
csswizardry
24
1.7k
Testing 201, or: Great Expectations
jmmastey
42
7.5k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
GraphQLの誤解/rethinking-graphql
sonatard
71
11k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
45
7.3k
Being A Developer After 40
akosma
90
590k
Rails Girls Zürich Keynote
gr2m
94
14k
Typedesign – Prime Four
hannesfritz
42
2.7k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
137
34k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.8k
Transcript
͋Δɺಥવϗετ໊͕ “MacBookPro” ʹͳͬͨ @niw 10/30/2024 — Tokyo, Japan ΰϦϥ.vim #33
Yoshimasa Niwa @niw
Vim ϢʔβʔͰ͢!
͋Δɺಥવϗετ໊͕ “MacBookPro” ʹͳͬͯ͠·ͬͨ
None
ͳͥ?
None
System Configuration Parameters macOS ͷઃఆ scutil --get --set ͰҎԼͷ3ͭઃఆ͕Ͱ͖Δ
ComputerName LocalHostName HostName
System Configuration Parameters macOS ͷઃఆ ComputerName Λ௨ৗઃఆ͢Δ LocalHostName σϑΥϧτͰ ComputerName
HostName ௨ৗ ”” (ۭനจࣈྻ) ɻDNS ͷٯҾ͖Ͱܾఆɻ hostname(1) gethostname(3) ͷ͜ͷ HostName
ͭ·Γ DNS ٯҾ͖͕ “MacBookPro” ʹͳ͍ͬͯΔ!
Α͋͘Δϧʔλͷڍಈ DNS ͷٯҾ͖ొ Α͋͘Δϧʔλ DHCP Ͱ IPv4 ΞυϨεΛΓͭͭɺDNS ͷϓϩΩγͱΩϟογϡΛ͢Δɻ ͜ͷDNS
ϓϩΩγ͕ͨ·ʹٯҾ͖ొΛ͢ΔλΠϓͷͷ ͕͋Δɻ dnsmasq ͳͲ͕࣮ྫɻ
https://thekelleys.org.uk/dnsmasq/docs/dnsmasq-man.html
None
None
None
DHCP Ͱ “MacBookPro” ͱ ͍͏ϗετ໊Λཁٻ͍ͯ͠Δ?
DHCPREQUEST Option 12 DHCP Ͱϗετ໊Λࢦఆ͢Δ ࠓ࣌ͷ DHCP RFC 2131
Dynamic Host Con fi guration Protocol Ͱنఆ͞ΕΔ ॴҦαʔόʔɾΫϥΠΞϯτϞσϧͰɺΫϥΠΞϯτͷཁٻ ʹαʔόʔ͕ IP ΞυϨε DNS αʔόͷΞυϨεΛฦ͢ Δ
-------- ------- | | +-------------------------->| |<-------------------+ | INIT- | |
+-------------------->| INIT | | | REBOOT |DHCPNAK/ +---------->| |<---+ | | |Restart| | ------- | | -------- | DHCPNAK/ | | | | Discard offer | -/Send DHCPDISCOVER | -/Send DHCPREQUEST | | | | | | DHCPACK v | | ----------- | (not accept.)/ ----------- | | | | | Send DHCPDECLINE | | | | REBOOTING | | | | SELECTING |<----+ | | | | / | | |DHCPOFFER/ | ----------- | / ----------- | |Collect | | | / | | | replies | DHCPACK/ | / +----------------+ +-------+ | Record lease, set| | v Select offer/ | timers T1, T2 ------------ send DHCPREQUEST | | | +----->| | DHCPNAK, Lease expired/ | | | | REQUESTING | Halt network | DHCPOFFER/ | | | | Discard ------------ | | | | | | ----------- | | +--------+ DHCPACK/ | | | | Record lease, set -----| REBINDING | | | timers T1, T2 / | | | | | DHCPACK/ ----------- | | v Record lease, set ^ | +----------------> ------- /timers T1,T2 | | +----->| |<---+ | | | | BOUND |<---+ | | DHCPOFFER, DHCPACK, | | | T2 expires/ DHCPNAK/ DHCPNAK/Discard ------- | Broadcast Halt network | | | | DHCPREQUEST | +-------+ | DHCPACK/ | | T1 expires/ Record lease, set | | Send DHCPREQUEST timers T1, T2 | | to leasing server | | | | ---------- | | | | |------------+ | +->| RENEWING | | | |----------------------------+ ---------- Figure 5: State-transition diagram for DHCP clients https://datatracker.ietf.org/doc/html/rfc2131
DHCPREQUEST Option 12 DHCP Ͱϗετ໊Λࢦఆ͢Δ ΫϥΠΞϯτ DHCPREQUEST ΛૹΓɺαʔόʔ DHCPACK Ͱ
IPΞυϨεΛฦ͢ DHCPREQUEST ʹΦϓγϣϯ͕͋ΓɺRFC 1533 Ͱنఆ͞ ΕΔ Host Name Option (Code = 12) Ͱϗετ໊ΛࢦఆͰ͖Δ
None
“MacBookPro” ͕ Option 12 Ͱࢦఆ͞Ε͍ͯΔ!
͍Ζ͍Ζ࿙ΕͯΔ Wi-Fi ͷϓϥΠόγʔ Wi-Fi ΘΓͱઅૢͳͦ͘ͷΜʹ͋ΔͷΛͬͯ͠·͏ Wi-Fi Ͱ IPv4 ௨৴͕Ͱ͖Δͷ DHCP
͕͋Δ͔Β ΫϥΞϯτ DHCP ʹ͍Ζ͍ΖใΛͯ͠͠·ͬͯΔ ϗετ໊͕ʮ୭ʑͷPCʯͩͱɺOption 12 ʹ୭ʑͷ෦͕ ೖ͍ͬͯͨΓͯ͠ɺIPΞυϨε͔Βݸਓ͕ಛఆͰ͖ΔՄೳੑ ͋Δ
͍Ζ͍Ζ࿙ΕͯΔ Wi-FiͷϓϥΠόγʔ ࣮ macOS 15 ͔Β DHCP ΫϥΠΞϯτͷ࣮͕มΘͬͯ ͍Δɻ σϑΥϧτͰɺWi-Fi
ܦ༝ͷ DHCPREQUEST ͷϗετ໊ ৗʹσόΠεͷछྨʹͳΔɻྫ͑ɺMacBookPro ɺ MacBookAir
https://github.com/apple-oss-distributions/bootp/blob/ main/IPCon fi guration.bproj/dhcp.c#L473-L487
https://github.com/apple-oss-distributions/bootp/blob/ main/IPCon fi guration.bproj/ipcon fi gd.c#L5405-L5408
https://github.com/apple-oss-distributions/bootp/blob/main/bootplib/interfaces.c#L872-L880
#define LOCAL_ADMIN 0x2 return addr->addr[0] & LOCAL_ADMIN) != 0;
2nd LSB of 1st octet of OUI MACΞυϨεϥϯμϚΠθʔγϣϯ iPhone
Mac ͷ MAC ΞυϨεσϑΥϧτͰϥϯμϚΠζ ͞Ε͍ͯΔ MAC ΞυϨε 64-bit ͋ͬͯɺ࠷ॳͷ 32-bit ϕϯμʔ͝ ͱʹܾ·͍ͬͯΔ ͜ΕΛ OUIs (Organizationally Unique Identi fi ers) ͱ͍͏
2nd LSB of 1st octet of OUI MACΞυϨεϥϯμϚΠθʔγϣϯ ࠷ॳͷόΠτͷԼ͔Β2൪ͷϏοτ OUI
ͷҰ෦ OUI ϝʔΧʔ͝ͱʹൃߦ͞Ε͍ͯΔ ·͔͞ɺApple ಛఆͷ OUI ϨϯδΛશ෦͍࣋ͬͯΔ?
IEEE 802-2001
2nd LSB of 1st octet of OUI MACΞυϨεϥϯμϚΠθʔγϣϯ ͭ͡ɺOUI ͷ࠷ॳͷόΠτͷԼ2Ϗοτ༧͞Ε͍ͯΔ
Լ͔Β1Ϗοτ༻్͕ܾ·͍ͬͯΔ Լ͔Β2ϏοτΊ0ͱܾ·͍ͬͯΔ ͭ·Γɺਖ਼نͷOUIͰɺԼ͔Β2Ϗοτ͕1ʹͳΔ͜ͱͳ ͍
None
$ irb irb(main):001> "f6:06:3a:90:bc:fe".split(/:/) .map{|s| "%08b" % s.to_i(16)}.join(" ") =>
"11110110 00000110 00111010 10010000 10111100 11111110"
None
$ irb irb(main):001> "f0:00:00:00:00:00".split(/:/) .map{|s| "%08b" % s.to_i(16)}.join(" ") =>
"11110000 00000000 00000000 00000000 00000000 00000000"
ϗετ໊͕ “MacBookPro” ʹͳͬͨཧ༝ ·ͱΊ MACΞυϨεͷϥϯμϚΠθʔγϣϯͷख๏ͰMACΞυϨε ͷ࠷ॳͷΦΫςοτͷԼ͔Β2Ϗοτ͕1ʹͳΔ͜ͱͰɺ DHCPΫϥΠΞϯτ͕ϓϥΠϕʔτΞυϨεͱஅ͠ɺσό ΠεͷϞσϧ໊ΛDHCPREQUESTͷOption 12ʹϗετ໊ͱ͠ ͯࢦఆ͢Δ͜ͱͰɺDHCPαʔόͱ࿈ಈ͢ΔDNSαʔό͕ͦ
ͷϞσϧ໊ΛٯҾ͖ొͨ݁͠ՌɺDNSΫϥΠΞϯτͷٯҾ ͖ղܾͰϞσϧ໊͕ฦ͖ͬͯͨҝ