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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Yoshimasa Niwa
October 30, 2024
0
300
ある日、突然ホスト名が “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
670
TextKit 2 時代の iOS のキーボードとテキスト入力と表示のすべて
niw
6
4.8k
Xcode が遅い! とにかく遅い!! 遅い Xcode をなんとかする方法
niw
1
9.4k
実践 iOS オープンソースプロジェクトの始め方
niw
6
3.5k
iOS のキーボードと文字入力のすべて
niw
14
3.4k
Getting started with making macOS utility app using private APIs
niw
3
2.9k
アプリの国際化の舞台裏
niw
11
8k
Lessons Learned
niw
6
5.2k
Getting Started with Scalding, Storm and Summingbird
niw
9
3k
Featured
See All Featured
The Language of Interfaces
destraynor
162
26k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
430
Scaling GitHub
holman
464
140k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
300
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
96
Information Architects: The Missing Link in Design Systems
soysaucechin
0
770
A better future with KSS
kneath
240
18k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.4k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
240
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.2k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
110
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
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ΫϥΠΞϯτͷٯҾ ͖ղܾͰϞσϧ໊͕ฦ͖ͬͯͨҝ