-2

packet arrives from application->...Network->(IP encapsulation added here as per IP configuration)->goes down to Data Link Layer Here the Framing is Done and SourceMac and Dest Mac is added for LAN Switching. Does every time the SourceMac is extracted from the HostNIC and encapsulated into the packet before sending out the interface? or there is some configuration file it reads from?

I am assuming /etc/network/interfaces file is empty and not having any hw-addr address to change the MAC[ifconfig eth0 hw ether (Macwe want tochange AA:BB:CC....) Command]. where does it gets its own MAC?

does it do a Lookup everytime say 'ifconfig eth0 |grep HWaddr' and fetches own MAC or similar via system call? coz that will add a huge overhead querying the NIC chipset everytime. Or does it maintain a file reads from it and simply encapsulates the packet coming from the upper layer and sends out from the wire?

user207421
  • 305,947
  • 44
  • 307
  • 483
  • The TCP/IP stack executes in the kernel, and all of the "state" is maintained in memory - no commands are executed or files read as part of packet transmission. – Jonathon Reinhart Nov 30 '14 at 06:09

1 Answers1

1

None of the above. The MAC adds its own address to Ethernet frames on the way out; the software doesn't have to add it.

On occasion, though, it is useful for the driver to know the physical address of the chip it's driving; this doesn't require querying the NIC every time or "maintaining a file"; 6 bytes of RAM in the driver's data structure does the job just fine. This is where the value displayed by ifconfig comes from.

hobbs
  • 223,387
  • 19
  • 210
  • 288
  • Okay. when we are using in /interfaces ifconfig eth0 hw ether AA:AA... Command. wat happens? the linux driver updates its 6bytes with new one and encapsulates with the same while sending out packets? – JusCuri0us Nov 30 '14 at 06:16
  • @JusCuri0us when you change the physical address, on hardware that supports it, it sends a command to the NIC to change the address stored in hardware registers on the MAC. The driver also updates its own value, of course. – hobbs Nov 30 '14 at 06:18