1use lock_order::lock::{DelegatedOrderedLockAccess, LockLevelFor};
6use lock_order::relation::LockBefore;
7use net_types::ip::{Ip, Ipv4, Ipv6};
8use netstack3_base::socket::MaybeDualStack;
9use netstack3_base::{
10 CoreTimerContext, CounterContext, ResourceCounterContext, Uninstantiable,
11 UninstantiableWrapper, WeakDeviceIdentifier,
12};
13use netstack3_datagram as datagram;
14use netstack3_device::WeakDeviceId;
15use netstack3_tcp::{
16 self as tcp, IsnGenerator, TcpContext, TcpCountersWithSocket, TcpCountersWithoutSocket,
17 TcpDemuxContext, TcpDualStackContext, TcpSocketId, TcpSocketSet, TcpSocketState,
18 WeakTcpSocketId,
19};
20use netstack3_udp::{
21 self as udp, UdpCountersWithSocket, UdpCountersWithoutSocket, UdpSocketId, UdpSocketSet,
22 UdpSocketState,
23};
24
25use crate::context::prelude::*;
26use crate::context::WrapLockLevel;
27use crate::transport::TransportLayerTimerId;
28use crate::{BindingsContext, BindingsTypes, CoreCtx, StackState};
29
30impl<I, BC, L> CoreTimerContext<WeakTcpSocketId<I, WeakDeviceId<BC>, BC>, BC> for CoreCtx<'_, BC, L>
31where
32 I: tcp::DualStackIpExt,
33 BC: BindingsContext,
34{
35 fn convert_timer(dispatch_id: WeakTcpSocketId<I, WeakDeviceId<BC>, BC>) -> BC::DispatchId {
36 TransportLayerTimerId::Tcp(dispatch_id.into()).into()
37 }
38}
39
40#[netstack3_macros::instantiate_ip_impl_block(I)]
41impl<I, L, BC> TcpDemuxContext<I, WeakDeviceId<BC>, BC> for CoreCtx<'_, BC, L>
42where
43 I: Ip,
44 BC: BindingsContext,
45 L: LockBefore<crate::lock_ordering::TcpDemux<I>>,
46{
47 type IpTransportCtx<'a> = CoreCtx<'a, BC, WrapLockLevel<crate::lock_ordering::TcpDemux<I>>>;
48 fn with_demux<O, F: FnOnce(&tcp::DemuxState<I, WeakDeviceId<BC>, BC>) -> O>(
49 &mut self,
50 cb: F,
51 ) -> O {
52 cb(&self.read_lock::<crate::lock_ordering::TcpDemux<I>>())
53 }
54
55 fn with_demux_mut<O, F: FnOnce(&mut tcp::DemuxState<I, WeakDeviceId<BC>, BC>) -> O>(
56 &mut self,
57 cb: F,
58 ) -> O {
59 cb(&mut self.write_lock::<crate::lock_ordering::TcpDemux<I>>())
60 }
61}
62
63impl<L, BC> TcpContext<Ipv4, BC> for CoreCtx<'_, BC, L>
64where
65 BC: BindingsContext,
66 L: LockBefore<crate::lock_ordering::TcpAllSocketsSet<Ipv4>>,
67{
68 type ThisStackIpTransportAndDemuxCtx<'a> =
69 CoreCtx<'a, BC, WrapLockLevel<crate::lock_ordering::TcpSocketState<Ipv4>>>;
70 type SingleStackIpTransportAndDemuxCtx<'a> =
71 CoreCtx<'a, BC, WrapLockLevel<crate::lock_ordering::TcpSocketState<Ipv4>>>;
72
73 type DualStackIpTransportAndDemuxCtx<'a> = UninstantiableWrapper<
74 CoreCtx<'a, BC, WrapLockLevel<crate::lock_ordering::TcpSocketState<Ipv4>>>,
75 >;
76
77 type SingleStackConverter = ();
78 type DualStackConverter = Uninstantiable;
79
80 fn with_all_sockets_mut<O, F: FnOnce(&mut TcpSocketSet<Ipv4, Self::WeakDeviceId, BC>) -> O>(
81 &mut self,
82 cb: F,
83 ) -> O {
84 let mut all_sockets = self.write_lock::<crate::lock_ordering::TcpAllSocketsSet<Ipv4>>();
85 cb(&mut *all_sockets)
86 }
87
88 fn for_each_socket<
89 F: FnMut(
90 &TcpSocketId<Ipv4, Self::WeakDeviceId, BC>,
91 &TcpSocketState<Ipv4, Self::WeakDeviceId, BC>,
92 ),
93 >(
94 &mut self,
95 mut cb: F,
96 ) {
97 let (all_sockets, mut locked) =
98 self.read_lock_and::<crate::lock_ordering::TcpAllSocketsSet<Ipv4>>();
99 all_sockets.keys().for_each(|id| {
100 let mut locked = locked.adopt(id);
101 let guard = locked
102 .read_lock_with::<crate::lock_ordering::TcpSocketState<Ipv4>, _>(|c| c.right());
103 cb(id, &*guard);
104 });
105 }
106
107 fn with_socket_mut_isn_transport_demux<
108 O,
109 F: for<'a> FnOnce(
110 MaybeDualStack<
111 (&'a mut Self::DualStackIpTransportAndDemuxCtx<'a>, Self::DualStackConverter),
112 (&'a mut Self::SingleStackIpTransportAndDemuxCtx<'a>, Self::SingleStackConverter),
113 >,
114 &mut TcpSocketState<Ipv4, Self::WeakDeviceId, BC>,
115 &IsnGenerator<BC::Instant>,
116 ) -> O,
117 >(
118 &mut self,
119 id: &TcpSocketId<Ipv4, Self::WeakDeviceId, BC>,
120 cb: F,
121 ) -> O {
122 let isn = &self
123 .unlocked_access::<crate::lock_ordering::UnlockedState>()
124 .transport
125 .tcp_state::<Ipv4>()
126 .isn_generator;
127 let mut locked = self.adopt(id);
128 let (mut socket_state, mut restricted) = locked
129 .write_lock_with_and::<crate::lock_ordering::TcpSocketState<Ipv4>, _>(|c| c.right());
130 let mut restricted = restricted.cast_core_ctx();
131 let maybe_dual_stack = MaybeDualStack::NotDualStack((&mut restricted, ()));
132 cb(maybe_dual_stack, &mut socket_state, isn)
133 }
134
135 fn with_socket_and_converter<
136 O,
137 F: FnOnce(
138 &TcpSocketState<Ipv4, Self::WeakDeviceId, BC>,
139 MaybeDualStack<Self::DualStackConverter, Self::SingleStackConverter>,
140 ) -> O,
141 >(
142 &mut self,
143 id: &TcpSocketId<Ipv4, Self::WeakDeviceId, BC>,
144 cb: F,
145 ) -> O {
146 let mut locked = self.adopt(id);
148 let socket_state =
149 locked.read_lock_with::<crate::lock_ordering::TcpSocketState<Ipv4>, _>(|c| c.right());
150 cb(&socket_state, MaybeDualStack::NotDualStack(()))
151 }
152}
153
154impl<L, BC> TcpContext<Ipv6, BC> for CoreCtx<'_, BC, L>
155where
156 BC: BindingsContext,
157 L: LockBefore<crate::lock_ordering::TcpAllSocketsSet<Ipv6>>,
158{
159 type ThisStackIpTransportAndDemuxCtx<'a> =
160 CoreCtx<'a, BC, WrapLockLevel<crate::lock_ordering::TcpSocketState<Ipv6>>>;
161 type SingleStackIpTransportAndDemuxCtx<'a> = UninstantiableWrapper<
162 CoreCtx<'a, BC, WrapLockLevel<crate::lock_ordering::TcpSocketState<Ipv6>>>,
163 >;
164
165 type DualStackIpTransportAndDemuxCtx<'a> =
166 CoreCtx<'a, BC, WrapLockLevel<crate::lock_ordering::TcpSocketState<Ipv6>>>;
167
168 type SingleStackConverter = Uninstantiable;
169 type DualStackConverter = ();
170
171 fn with_all_sockets_mut<O, F: FnOnce(&mut TcpSocketSet<Ipv6, Self::WeakDeviceId, BC>) -> O>(
172 &mut self,
173 cb: F,
174 ) -> O {
175 let mut all_sockets = self.write_lock::<crate::lock_ordering::TcpAllSocketsSet<Ipv6>>();
176 cb(&mut *all_sockets)
177 }
178
179 fn for_each_socket<
180 F: FnMut(
181 &TcpSocketId<Ipv6, Self::WeakDeviceId, BC>,
182 &TcpSocketState<Ipv6, Self::WeakDeviceId, BC>,
183 ),
184 >(
185 &mut self,
186 mut cb: F,
187 ) {
188 let (all_sockets, mut locked) =
189 self.read_lock_and::<crate::lock_ordering::TcpAllSocketsSet<Ipv6>>();
190 all_sockets.keys().for_each(|id| {
191 let mut locked = locked.adopt(id);
192 let guard = locked
193 .read_lock_with::<crate::lock_ordering::TcpSocketState<Ipv6>, _>(|c| c.right());
194 cb(id, &*guard);
195 });
196 }
197
198 fn with_socket_mut_isn_transport_demux<
199 O,
200 F: for<'a> FnOnce(
201 MaybeDualStack<
202 (&'a mut Self::DualStackIpTransportAndDemuxCtx<'a>, Self::DualStackConverter),
203 (&'a mut Self::SingleStackIpTransportAndDemuxCtx<'a>, Self::SingleStackConverter),
204 >,
205 &mut TcpSocketState<Ipv6, Self::WeakDeviceId, BC>,
206 &IsnGenerator<BC::Instant>,
207 ) -> O,
208 >(
209 &mut self,
210 id: &TcpSocketId<Ipv6, Self::WeakDeviceId, BC>,
211 cb: F,
212 ) -> O {
213 let isn = &self
214 .unlocked_access::<crate::lock_ordering::UnlockedState>()
215 .transport
216 .tcp_state::<Ipv6>()
217 .isn_generator;
218 let mut locked = self.adopt(id);
219 let (mut socket_state, mut restricted) = locked
220 .write_lock_with_and::<crate::lock_ordering::TcpSocketState<Ipv6>, _>(|c| c.right());
221 let mut restricted = restricted.cast_core_ctx();
222 let maybe_dual_stack = MaybeDualStack::DualStack((&mut restricted, ()));
223 cb(maybe_dual_stack, &mut socket_state, isn)
224 }
225
226 fn with_socket_and_converter<
227 O,
228 F: FnOnce(
229 &TcpSocketState<Ipv6, Self::WeakDeviceId, BC>,
230 MaybeDualStack<Self::DualStackConverter, Self::SingleStackConverter>,
231 ) -> O,
232 >(
233 &mut self,
234 id: &TcpSocketId<Ipv6, Self::WeakDeviceId, BC>,
235 cb: F,
236 ) -> O {
237 let mut locked = self.adopt(id);
239 let socket_state =
240 locked.read_lock_with::<crate::lock_ordering::TcpSocketState<Ipv6>, _>(|c| c.right());
241 cb(&socket_state, MaybeDualStack::DualStack(()))
242 }
243}
244
245impl<L: LockBefore<crate::lock_ordering::TcpDemux<Ipv4>>, BC: BindingsContext>
246 TcpDualStackContext<Ipv6, WeakDeviceId<BC>, BC> for CoreCtx<'_, BC, L>
247{
248 type DualStackIpTransportCtx<'a> =
249 CoreCtx<'a, BC, WrapLockLevel<crate::lock_ordering::TcpDemux<Ipv6>>>;
250 fn other_demux_id_converter(&self) -> impl tcp::DualStackDemuxIdConverter<Ipv6> {
251 tcp::Ipv6SocketIdToIpv4DemuxIdConverter
252 }
253
254 fn dual_stack_enabled(&self, ip_options: &tcp::Ipv6Options) -> bool {
255 ip_options.dual_stack_enabled
256 }
257
258 fn set_dual_stack_enabled(&self, ip_options: &mut tcp::Ipv6Options, value: bool) {
259 ip_options.dual_stack_enabled = value;
260 }
261
262 fn with_both_demux_mut<
263 O,
264 F: FnOnce(
265 &mut tcp::DemuxState<Ipv6, WeakDeviceId<BC>, BC>,
266 &mut tcp::DemuxState<Ipv4, WeakDeviceId<BC>, BC>,
267 ) -> O,
268 >(
269 &mut self,
270 cb: F,
271 ) -> O {
272 let (mut demux_v4, mut locked) =
273 self.write_lock_and::<crate::lock_ordering::TcpDemux<Ipv4>>();
274 let mut demux_v6 = locked.write_lock::<crate::lock_ordering::TcpDemux<Ipv6>>();
275 cb(&mut demux_v6, &mut demux_v4)
276 }
277}
278
279#[netstack3_macros::instantiate_ip_impl_block(I)]
280impl<I: Ip, BC: BindingsContext, L: LockBefore<crate::lock_ordering::UdpAllSocketsSet<I>>>
281 udp::StateContext<I, BC> for CoreCtx<'_, BC, L>
282{
283 type SocketStateCtx<'a> =
284 CoreCtx<'a, BC, WrapLockLevel<crate::lock_ordering::UdpSocketState<I>>>;
285
286 fn with_bound_state_context<O, F: FnOnce(&mut Self::SocketStateCtx<'_>) -> O>(
287 &mut self,
288 cb: F,
289 ) -> O {
290 cb(&mut self.cast_locked::<crate::lock_ordering::UdpSocketState<I>>())
291 }
292
293 fn with_all_sockets_mut<O, F: FnOnce(&mut UdpSocketSet<I, Self::WeakDeviceId, BC>) -> O>(
294 &mut self,
295 cb: F,
296 ) -> O {
297 cb(&mut self.write_lock::<crate::lock_ordering::UdpAllSocketsSet<I>>())
298 }
299
300 fn with_all_sockets<O, F: FnOnce(&UdpSocketSet<I, Self::WeakDeviceId, BC>) -> O>(
301 &mut self,
302 cb: F,
303 ) -> O {
304 cb(&self.read_lock::<crate::lock_ordering::UdpAllSocketsSet<I>>())
305 }
306
307 fn with_socket_state<
308 O,
309 F: FnOnce(&mut Self::SocketStateCtx<'_>, &UdpSocketState<I, Self::WeakDeviceId, BC>) -> O,
310 >(
311 &mut self,
312 id: &UdpSocketId<I, Self::WeakDeviceId, BC>,
313 cb: F,
314 ) -> O {
315 let mut locked = self.adopt(id);
316 let (socket_state, mut restricted) =
317 locked.read_lock_with_and::<crate::lock_ordering::UdpSocketState<I>, _>(|c| c.right());
318 let mut restricted = restricted.cast_core_ctx();
319 cb(&mut restricted, &socket_state)
320 }
321
322 fn with_socket_state_mut<
323 O,
324 F: FnOnce(&mut Self::SocketStateCtx<'_>, &mut UdpSocketState<I, Self::WeakDeviceId, BC>) -> O,
325 >(
326 &mut self,
327 id: &UdpSocketId<I, Self::WeakDeviceId, BC>,
328 cb: F,
329 ) -> O {
330 let mut locked = self.adopt(id);
331 let (mut socket_state, mut restricted) =
332 locked.write_lock_with_and::<crate::lock_ordering::UdpSocketState<I>, _>(|c| c.right());
333 let mut restricted = restricted.cast_core_ctx();
334 cb(&mut restricted, &mut socket_state)
335 }
336
337 fn for_each_socket<
338 F: FnMut(
339 &mut Self::SocketStateCtx<'_>,
340 &UdpSocketId<I, Self::WeakDeviceId, BC>,
341 &UdpSocketState<I, Self::WeakDeviceId, BC>,
342 ),
343 >(
344 &mut self,
345 mut cb: F,
346 ) {
347 let (all_sockets, mut locked) =
348 self.read_lock_and::<crate::lock_ordering::UdpAllSocketsSet<I>>();
349 all_sockets.keys().for_each(|id| {
350 let id = UdpSocketId::from(id.clone());
351 let mut locked = locked.adopt(&id);
352 let (socket_state, mut restricted) = locked
353 .read_lock_with_and::<crate::lock_ordering::UdpSocketState<I>, _>(|c| c.right());
354 let mut restricted = restricted.cast_core_ctx();
355 cb(&mut restricted, &id, &socket_state);
356 });
357 }
358}
359
360impl<BC: BindingsContext, L: LockBefore<crate::lock_ordering::UdpBoundMap<Ipv4>>>
361 udp::BoundStateContext<Ipv4, BC> for CoreCtx<'_, BC, L>
362{
363 type IpSocketsCtx<'a> = CoreCtx<'a, BC, WrapLockLevel<crate::lock_ordering::UdpBoundMap<Ipv4>>>;
364 type DualStackContext = UninstantiableWrapper<Self>;
365 type NonDualStackContext = Self;
366
367 fn with_bound_sockets<
368 O,
369 F: FnOnce(&mut Self::IpSocketsCtx<'_>, &udp::BoundSockets<Ipv4, Self::WeakDeviceId, BC>) -> O,
370 >(
371 &mut self,
372 cb: F,
373 ) -> O {
374 let (bound_sockets, mut locked) =
375 self.read_lock_and::<crate::lock_ordering::UdpBoundMap<Ipv4>>();
376 cb(&mut locked, &bound_sockets)
377 }
378
379 fn with_bound_sockets_mut<
380 O,
381 F: FnOnce(
382 &mut Self::IpSocketsCtx<'_>,
383 &mut udp::BoundSockets<Ipv4, Self::WeakDeviceId, BC>,
384 ) -> O,
385 >(
386 &mut self,
387 cb: F,
388 ) -> O {
389 let (mut bound_sockets, mut locked) =
390 self.write_lock_and::<crate::lock_ordering::UdpBoundMap<Ipv4>>();
391 cb(&mut locked, &mut bound_sockets)
392 }
393
394 fn dual_stack_context(
395 &mut self,
396 ) -> MaybeDualStack<&mut Self::DualStackContext, &mut Self::NonDualStackContext> {
397 MaybeDualStack::NotDualStack(self)
398 }
399
400 fn with_transport_context<O, F: FnOnce(&mut Self::IpSocketsCtx<'_>) -> O>(
401 &mut self,
402 cb: F,
403 ) -> O {
404 cb(&mut self.cast_locked())
405 }
406}
407
408impl<BC: BindingsContext, L: LockBefore<crate::lock_ordering::UdpBoundMap<Ipv4>>>
409 udp::BoundStateContext<Ipv6, BC> for CoreCtx<'_, BC, L>
410{
411 type IpSocketsCtx<'a> = CoreCtx<'a, BC, WrapLockLevel<crate::lock_ordering::UdpBoundMap<Ipv6>>>;
412 type DualStackContext = Self;
413 type NonDualStackContext = UninstantiableWrapper<Self>;
414
415 fn with_bound_sockets<
416 O,
417 F: FnOnce(&mut Self::IpSocketsCtx<'_>, &udp::BoundSockets<Ipv6, Self::WeakDeviceId, BC>) -> O,
418 >(
419 &mut self,
420 cb: F,
421 ) -> O {
422 let (bound_sockets, mut locked) =
423 self.read_lock_and::<crate::lock_ordering::UdpBoundMap<Ipv6>>();
424 cb(&mut locked, &bound_sockets)
425 }
426
427 fn with_bound_sockets_mut<
428 O,
429 F: FnOnce(
430 &mut Self::IpSocketsCtx<'_>,
431 &mut udp::BoundSockets<Ipv6, Self::WeakDeviceId, BC>,
432 ) -> O,
433 >(
434 &mut self,
435 cb: F,
436 ) -> O {
437 let (mut bound_sockets, mut locked) =
438 self.write_lock_and::<crate::lock_ordering::UdpBoundMap<Ipv6>>();
439 cb(&mut locked, &mut bound_sockets)
440 }
441
442 fn dual_stack_context(
443 &mut self,
444 ) -> MaybeDualStack<&mut Self::DualStackContext, &mut Self::NonDualStackContext> {
445 MaybeDualStack::DualStack(self)
446 }
447
448 fn with_transport_context<O, F: FnOnce(&mut Self::IpSocketsCtx<'_>) -> O>(
449 &mut self,
450 cb: F,
451 ) -> O {
452 cb(&mut self.cast_locked::<crate::lock_ordering::UdpBoundMap<Ipv6>>())
453 }
454}
455
456impl<L, BC: BindingsContext> udp::UdpStateContext for CoreCtx<'_, BC, L> {}
457
458impl<BC: BindingsContext, L: LockBefore<crate::lock_ordering::UdpBoundMap<Ipv4>>>
459 udp::DualStackBoundStateContext<Ipv6, BC> for CoreCtx<'_, BC, L>
460{
461 type IpSocketsCtx<'a> = CoreCtx<'a, BC, WrapLockLevel<crate::lock_ordering::UdpBoundMap<Ipv6>>>;
462
463 fn with_both_bound_sockets_mut<
464 O,
465 F: FnOnce(
466 &mut Self::IpSocketsCtx<'_>,
467 &mut udp::BoundSockets<Ipv6, Self::WeakDeviceId, BC>,
468 &mut udp::BoundSockets<Ipv4, Self::WeakDeviceId, BC>,
469 ) -> O,
470 >(
471 &mut self,
472 cb: F,
473 ) -> O {
474 let (mut bound_v4, mut locked) =
475 self.write_lock_and::<crate::lock_ordering::UdpBoundMap<Ipv4>>();
476 let (mut bound_v6, mut locked) =
477 locked.write_lock_and::<crate::lock_ordering::UdpBoundMap<Ipv6>>();
478 cb(&mut locked, &mut bound_v6, &mut bound_v4)
479 }
480
481 fn with_other_bound_sockets_mut<
482 O,
483 F: FnOnce(
484 &mut Self::IpSocketsCtx<'_>,
485 &mut udp::BoundSockets<Ipv4, Self::WeakDeviceId, BC>,
486 ) -> O,
487 >(
488 &mut self,
489 cb: F,
490 ) -> O {
491 let (mut bound_v4, mut locked) =
492 self.write_lock_and::<crate::lock_ordering::UdpBoundMap<Ipv4>>();
493 cb(&mut locked.cast_locked::<crate::lock_ordering::UdpBoundMap<Ipv6>>(), &mut bound_v4)
494 }
495
496 fn with_transport_context<O, F: FnOnce(&mut Self::IpSocketsCtx<'_>) -> O>(
497 &mut self,
498 cb: F,
499 ) -> O {
500 cb(&mut self.cast_locked::<crate::lock_ordering::UdpBoundMap<Ipv6>>())
501 }
502}
503
504impl<BC: BindingsContext, L: LockBefore<crate::lock_ordering::UdpBoundMap<Ipv4>>>
505 udp::NonDualStackBoundStateContext<Ipv4, BC> for CoreCtx<'_, BC, L>
506{
507}
508
509impl<I: tcp::DualStackIpExt, BT: BindingsTypes> LockLevelFor<StackState<BT>>
510 for crate::lock_ordering::TcpAllSocketsSet<I>
511{
512 type Data = TcpSocketSet<I, WeakDeviceId<BT>, BT>;
513}
514
515impl<I: tcp::DualStackIpExt, BT: BindingsTypes>
516 DelegatedOrderedLockAccess<TcpSocketSet<I, WeakDeviceId<BT>, BT>> for StackState<BT>
517{
518 type Inner = tcp::Sockets<I, WeakDeviceId<BT>, BT>;
519 fn delegate_ordered_lock_access(&self) -> &Self::Inner {
520 &self.transport.tcp_state::<I>().sockets
521 }
522}
523
524impl<I: tcp::DualStackIpExt, BT: BindingsTypes> LockLevelFor<StackState<BT>>
525 for crate::lock_ordering::TcpDemux<I>
526{
527 type Data = tcp::DemuxState<I, WeakDeviceId<BT>, BT>;
528}
529
530impl<I: tcp::DualStackIpExt, BT: BindingsTypes>
531 DelegatedOrderedLockAccess<tcp::DemuxState<I, WeakDeviceId<BT>, BT>> for StackState<BT>
532{
533 type Inner = tcp::Sockets<I, WeakDeviceId<BT>, BT>;
534 fn delegate_ordered_lock_access(&self) -> &Self::Inner {
535 &self.transport.tcp_state::<I>().sockets
536 }
537}
538
539impl<I: crate::transport::tcp::DualStackIpExt, D: WeakDeviceIdentifier, BT: BindingsTypes>
540 LockLevelFor<TcpSocketId<I, D, BT>> for crate::lock_ordering::TcpSocketState<I>
541{
542 type Data = TcpSocketState<I, D, BT>;
543}
544
545impl<I: datagram::IpExt, D: WeakDeviceIdentifier, BT: BindingsTypes>
546 LockLevelFor<UdpSocketId<I, D, BT>> for crate::lock_ordering::UdpSocketState<I>
547{
548 type Data = UdpSocketState<I, D, BT>;
549}
550
551impl<I: datagram::IpExt, BT: BindingsTypes> LockLevelFor<StackState<BT>>
552 for crate::lock_ordering::UdpBoundMap<I>
553{
554 type Data = udp::BoundSockets<I, WeakDeviceId<BT>, BT>;
555}
556
557impl<I: datagram::IpExt, BT: BindingsTypes>
558 DelegatedOrderedLockAccess<udp::BoundSockets<I, WeakDeviceId<BT>, BT>> for StackState<BT>
559{
560 type Inner = udp::Sockets<I, WeakDeviceId<BT>, BT>;
561 fn delegate_ordered_lock_access(&self) -> &Self::Inner {
562 &self.transport.udp_state::<I>().sockets
563 }
564}
565
566impl<I: datagram::IpExt, BT: BindingsTypes> LockLevelFor<StackState<BT>>
567 for crate::lock_ordering::UdpAllSocketsSet<I>
568{
569 type Data = UdpSocketSet<I, WeakDeviceId<BT>, BT>;
570}
571
572impl<I: datagram::IpExt, BT: BindingsTypes>
573 DelegatedOrderedLockAccess<UdpSocketSet<I, WeakDeviceId<BT>, BT>> for StackState<BT>
574{
575 type Inner = udp::Sockets<I, WeakDeviceId<BT>, BT>;
576 fn delegate_ordered_lock_access(&self) -> &Self::Inner {
577 &self.transport.udp_state::<I>().sockets
578 }
579}
580
581impl<BC: BindingsContext, I: Ip, L> CounterContext<TcpCountersWithSocket<I>>
582 for CoreCtx<'_, BC, L>
583{
584 fn counters(&self) -> &TcpCountersWithSocket<I> {
585 self.unlocked_access::<crate::lock_ordering::UnlockedState>()
586 .transport
587 .tcp_counters_with_socket::<I>()
588 }
589}
590
591impl<BC: BindingsContext, I: Ip, L> CounterContext<TcpCountersWithoutSocket<I>>
592 for CoreCtx<'_, BC, L>
593{
594 fn counters(&self) -> &TcpCountersWithoutSocket<I> {
595 self.unlocked_access::<crate::lock_ordering::UnlockedState>()
596 .transport
597 .tcp_counters_without_socket::<I>()
598 }
599}
600
601impl<BC: BindingsContext, I: netstack3_tcp::DualStackIpExt, L>
602 ResourceCounterContext<TcpSocketId<I, WeakDeviceId<BC>, BC>, TcpCountersWithSocket<I>>
603 for CoreCtx<'_, BC, L>
604{
605 fn per_resource_counters<'a>(
606 &'a self,
607 resource: &'a TcpSocketId<I, WeakDeviceId<BC>, BC>,
608 ) -> &'a TcpCountersWithSocket<I> {
609 resource.counters()
610 }
611}
612
613impl<BC: BindingsContext, I: Ip, L> CounterContext<UdpCountersWithSocket<I>>
614 for CoreCtx<'_, BC, L>
615{
616 fn counters(&self) -> &UdpCountersWithSocket<I> {
617 self.unlocked_access::<crate::lock_ordering::UnlockedState>()
618 .transport
619 .udp_counters_with_socket::<I>()
620 }
621}
622
623impl<BC: BindingsContext, I: Ip, L> CounterContext<UdpCountersWithoutSocket<I>>
624 for CoreCtx<'_, BC, L>
625{
626 fn counters(&self) -> &UdpCountersWithoutSocket<I> {
627 self.unlocked_access::<crate::lock_ordering::UnlockedState>()
628 .transport
629 .udp_counters_without_socket::<I>()
630 }
631}
632
633impl<BC: BindingsContext, I: netstack3_datagram::IpExt, L>
634 ResourceCounterContext<UdpSocketId<I, WeakDeviceId<BC>, BC>, UdpCountersWithSocket<I>>
635 for CoreCtx<'_, BC, L>
636{
637 fn per_resource_counters<'a>(
638 &'a self,
639 resource: &'a UdpSocketId<I, WeakDeviceId<BC>, BC>,
640 ) -> &'a UdpCountersWithSocket<I> {
641 resource.counters()
642 }
643}