1 /** @file
2 * @brief IPv4/6 PMTU related functions
3 */
4
5 /*
6 * Copyright (c) 2024 Nordic Semiconductor
7 *
8 * SPDX-License-Identifier: Apache-2.0
9 */
10 #ifndef __NET_PMTU_H
11 #define __NET_PMTU_H
12
13 #include <zephyr/net/net_ip.h>
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 /** PTMU destination cache entry */
20 struct net_pmtu_entry {
21 /** Destination address */
22 struct net_addr dst;
23 /** Last time the PMTU was updated */
24 uint32_t last_update;
25 /** MTU for this destination address */
26 uint16_t mtu;
27 /** In use flag */
28 bool in_use : 1;
29 };
30
31 /** Get PMTU entry for the given destination address
32 *
33 * @param dst Destination address
34 *
35 * @return PMTU entry if found, NULL otherwise
36 */
37 #if defined(CONFIG_NET_PMTU)
38 struct net_pmtu_entry *net_pmtu_get_entry(const struct sockaddr *dst);
39 #else
net_pmtu_get_entry(const struct sockaddr * dst)40 static inline struct net_pmtu_entry *net_pmtu_get_entry(const struct sockaddr *dst)
41 {
42 ARG_UNUSED(dst);
43
44 return NULL;
45 }
46 #endif /* CONFIG_NET_PMTU */
47
48 /** Get MTU value for the given destination address
49 *
50 * @param dst Destination address
51 *
52 * @return MTU value (> 0) if found, <0 otherwise
53 */
54 #if defined(CONFIG_NET_PMTU)
55 int net_pmtu_get_mtu(const struct sockaddr *dst);
56 #else
net_pmtu_get_mtu(const struct sockaddr * dst)57 static inline int net_pmtu_get_mtu(const struct sockaddr *dst)
58 {
59 ARG_UNUSED(dst);
60
61 return -ENOTSUP;
62 }
63 #endif /* CONFIG_NET_PMTU */
64
65 /** Update PMTU value for the given destination address
66 *
67 * @param dst Destination address
68 * @param mtu New MTU value
69 *
70 * @return >0 previous MTU, <0 if error
71 */
72 #if defined(CONFIG_NET_PMTU)
73 int net_pmtu_update_mtu(const struct sockaddr *dst, uint16_t mtu);
74 #else
net_pmtu_update_mtu(const struct sockaddr * dst,uint16_t mtu)75 static inline int net_pmtu_update_mtu(const struct sockaddr *dst, uint16_t mtu)
76 {
77 ARG_UNUSED(dst);
78 ARG_UNUSED(mtu);
79
80 return -ENOTSUP;
81 }
82 #endif /* CONFIG_NET_PMTU */
83
84 /** Update PMTU entry for the given destination address
85 *
86 * @param entry PMTU entry
87 * @param mtu New MTU value
88 *
89 * @return >0 previous MTU, <0 if error
90 */
91 #if defined(CONFIG_NET_PMTU)
92 int net_pmtu_update_entry(struct net_pmtu_entry *entry, uint16_t mtu);
93 #else
net_pmtu_update_entry(struct net_pmtu_entry * entry,uint16_t mtu)94 static inline int net_pmtu_update_entry(struct net_pmtu_entry *entry,
95 uint16_t mtu)
96 {
97 ARG_UNUSED(entry);
98 ARG_UNUSED(mtu);
99
100 return -ENOTSUP;
101 }
102 #endif /* CONFIG_NET_PMTU */
103
104 /**
105 * @typedef net_pmtu_cb_t
106 * @brief Callback used when traversing PMTU destination cache.
107 *
108 * @param entry PMTU entry
109 * @param user_data User specified data
110 */
111 typedef void (*net_pmtu_cb_t)(struct net_pmtu_entry *entry,
112 void *user_data);
113
114 /** Get PMTU destination cache contents
115 *
116 * @param cb PMTU callback to be called for each cache entry.
117 * @param user_data User specific data.
118 *
119 * @return >=0 number of entries in the PMTU destination cache, <0 if error
120 */
121 #if defined(CONFIG_NET_PMTU)
122 int net_pmtu_foreach(net_pmtu_cb_t cb, void *user_data);
123 #else
net_pmtu_foreach(net_pmtu_cb_t cb,void * user_data)124 static inline int net_pmtu_foreach(net_pmtu_cb_t cb, void *user_data)
125 {
126 ARG_UNUSED(cb);
127 ARG_UNUSED(user_data);
128
129 return -ENOTSUP;
130 }
131 #endif /* CONFIG_NET_PMTU */
132
133 /** Initialize PMTU module */
134 #if defined(CONFIG_NET_PMTU)
135 void net_pmtu_init(void);
136 #else
137 #define net_pmtu_init(...)
138 #endif
139
140 #ifdef __cplusplus
141 }
142 #endif
143
144 #endif /* __NET_PMTU_H */
145