public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
4e4e0bf5953cf86f41ffb3acf350ef69041d7b09 blob 1527 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
 
// SPDX-License-Identifier: GPL-2.0-or-later

/* PASST - Plug A Simple Socket Transport
 *  for qemu/UNIX domain socket mode
 *
 * PASTA - Pack A Subtle Tap Abstraction
 *  for network namespace/tap device mode
 *
 * PESTO - Programmable Extensible Socket Translation Orchestrator
 *  front-end for passt(1) and pasta(1) forwarding configuration
 *
 * ip.c - IP related functions
 *
 * Copyright (c) 2020-2021 Red Hat GmbH
 * Author: Stefano Brivio <sbrivio@redhat.com>
 */

#include <stddef.h>
#include <netinet/in.h>

#include "ip.h"

/**
 * ipproto_name() - Get IP protocol name from number
 * @proto:	IP protocol number
 *
 * Return: pointer to name of protocol @proto
 *
 * Usually this would be done with getprotobynumber(3) but that reads
 * /etc/protocols and might allocate, which isn't possible for us once
 * self-isolated.
 */
const char *ipproto_name(uint8_t proto)
{
	switch (proto) {
	case IPPROTO_ICMP:
		return "ICMP";
	case IPPROTO_TCP:
		return "TCP";
	case IPPROTO_UDP:
		return "UDP";
	case IPPROTO_ICMPV6:
		return "ICMPv6";
	default:
		return "<unknown protocol>";
	}
}

/**
 * ip4_class_prefix_len() - Get class based prefix length for IPv4 address
 * @addr:	IPv4 address
 *
 * Return: prefix length based on address class, or 32 for other
 */
int ip4_class_prefix_len(const struct in_addr *addr)
{
	in_addr_t a = ntohl(addr->s_addr);

	if (IN_CLASSA(a))
		return 32 - IN_CLASSA_NSHIFT;
	if (IN_CLASSB(a))
		return 32 - IN_CLASSB_NSHIFT;
	if (IN_CLASSC(a))
		return 32 - IN_CLASSC_NSHIFT;
	return 32;
}
debug log:

solving 4e4e0bf5 ...
found 4e4e0bf5 in https://archives.passt.top/passt-dev/20260319061157.1983818-11-david@gibson.dropbear.id.au/
found 0ea62998 in https://passt.top/passt
preparing index
index prepared:
100644 0ea62998095cfebd622ad550f1d09ec689170df7	ip.c

applying [1/1] https://archives.passt.top/passt-dev/20260319061157.1983818-11-david@gibson.dropbear.id.au/
diff --git a/ip.c b/ip.c
index 0ea62998..4e4e0bf5 100644

Checking patch ip.c...
Applied patch ip.c cleanly.

index at:
100644 4e4e0bf5953cf86f41ffb3acf350ef69041d7b09	ip.c

Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).