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?
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.