net/ipv4/ipconfig.c

Source file repositories/reference/linux-study-clean/net/ipv4/ipconfig.c

File Facts

System
Linux kernel
Corpus path
net/ipv4/ipconfig.c
Extension
.c
Size
44288 bytes
Lines
1848
Domain
Networking Core
Bucket
Sockets, Protocols, Packet Path, And Network Policy
Inferred role
Networking Core: implementation source
Status
source implementation candidate

Why This File Exists

Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.

Dependency Surface

Detected Declarations

Annotated Snippet

struct ic_device {
	struct ic_device *next;
	struct net_device *dev;
	unsigned short flags;
	short able;
	__be32 xid;
};

static struct ic_device *ic_first_dev __initdata;	/* List of open device */
static struct ic_device *ic_dev __initdata;		/* Selected device */

static bool __init ic_is_init_dev(struct net_device *dev)
{
	if (dev->flags & IFF_LOOPBACK)
		return false;
	return user_dev_name[0] ? !strcmp(dev->name, user_dev_name) :
	    (!(dev->flags & IFF_LOOPBACK) &&
	     (dev->flags & (IFF_POINTOPOINT|IFF_BROADCAST)) &&
	     strncmp(dev->name, "dummy", 5));
}

static int __init ic_open_devs(void)
{
	struct ic_device *d, **last;
	struct net_device *dev;
	unsigned short oflags;
	unsigned long start, next_msg;

	last = &ic_first_dev;
	rtnl_lock();

	/* bring loopback device up first */
	for_each_netdev(&init_net, dev) {
		if (!(dev->flags & IFF_LOOPBACK))
			continue;
		if (dev_change_flags(dev, dev->flags | IFF_UP, NULL) < 0)
			pr_err("IP-Config: Failed to open %s\n", dev->name);
	}

	for_each_netdev(&init_net, dev) {
		if (ic_is_init_dev(dev)) {
			int able = 0;
			if (dev->mtu >= 364)
				able |= IC_BOOTP;
			else
				pr_warn("DHCP/BOOTP: Ignoring device %s, MTU %d too small\n",
					dev->name, dev->mtu);
			if (!(dev->flags & IFF_NOARP))
				able |= IC_RARP;
			able &= ic_proto_enabled;
			if (ic_proto_enabled && !able)
				continue;
			oflags = dev->flags;
			if (dev_change_flags(dev, oflags | IFF_UP, NULL) < 0) {
				pr_err("IP-Config: Failed to open %s\n",
				       dev->name);
				continue;
			}
			if (!(d = kmalloc_obj(struct ic_device))) {
				rtnl_unlock();
				return -ENOMEM;
			}
			d->dev = dev;
			*last = d;
			last = &d->next;
			d->flags = oflags;
			d->able = able;
			if (able & IC_BOOTP)
				get_random_bytes(&d->xid, sizeof(__be32));
			else
				d->xid = 0;
			ic_proto_have_if |= able;
			pr_debug("IP-Config: %s UP (able=%d, xid=%08x)\n",
				 dev->name, able, d->xid);
		}
	}
	/* Devices with a complex topology like SFP ethernet interfaces needs
	 * the rtnl_lock at init. The carrier wait-loop must therefore run
	 * without holding it.
	 */
	rtnl_unlock();

	/* no point in waiting if we could not bring up at least one device */
	if (!ic_first_dev)
		goto have_carrier;

	/* wait for a carrier on at least one device */
	start = jiffies;
	next_msg = start + secs_to_jiffies(20);
	while (time_before(jiffies, start +

Annotation

Implementation Notes