Skip to Content
Understanding Linux Network Internals
book

Understanding Linux Network Internals

by Christian Benvenuti
December 2005
Intermediate to advanced
1066 pages
33h 38m
English
O'Reilly Media, Inc.
Content preview from Understanding Linux Network Internals

Primary and Secondary IP Addresses

We saw in the section "Primary and Secondary Addresses" in Chapter 30 that an IP address can be configured as primary or secondary on a device. The kernel often needs to browse all the addresses configured on a device to find one that matches a given condition. Let's see how the two types of addresses are distinguished and how addresses are browsed.

Secondary IPv4 addresses are tagged with the IFA_F_SECONDARY flag in their in_ifaddr data structures (see Chapter 19). Because there are only two configurations—primary and secondary—there is no need for an IFA_F_PRIMARY flag: if an address is not secondary, it is considered primary.

The kernel provides macros in include/linux/inetdevice.h that make it easier to browse interfaces meeting specific criteria. For each criterion selected, there are usually two macros that are used to bracket a loop: the programmer places the code to process a single address in a block that is started by one macro and terminated by another. The effect is to run a loop applying the code to each address meeting selected criteria.

Here is an example of the macros in use:

for_ifa {
 
        do something with ifa
 
} endfor_ifa

The for_ifa macro starts a loop with the variable ifa to represent each address selected. The code between the macros does not need to be placed in brackets, but it usually is, to make variables such as ifa local and usable only within the loop.

A few such macros include:

for_ifa
endfor_ifa

Given a device, these two ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Linux Kernel Debugging

Linux Kernel Debugging

Kaiwan N. Billimoria
Linux Kernel Programming

Linux Kernel Programming

Kaiwan N. Billimoria

Publisher Resources

ISBN: 0596002556Errata Page