Skip to content

Commit 474b63d

Browse files
authored
Merge pull request #19 from AndriiFullroot/SESSION_HOOKS
T8010: VPP plugin and session hooks interface
2 parents cda32aa + bfeab4b commit 474b63d

30 files changed

Lines changed: 755 additions & 396 deletions

accel-pppd/CMakeLists.txt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ IF (HAVE_VPP)
8989
ADD_DEFINITIONS(-DHAVE_VPP)
9090
ENDIF (HAVE_VPP)
9191

92+
IF (HAVE_SESSION_HOOKS)
93+
ADD_DEFINITIONS(-DHAVE_SESSION_HOOKS)
94+
ENDIF (HAVE_SESSION_HOOKS)
95+
9296
ADD_SUBDIRECTORY(triton)
9397
ADD_SUBDIRECTORY(vlan-mon)
9498
ADD_SUBDIRECTORY(ctrl)
@@ -177,17 +181,11 @@ ADD_EXECUTABLE(accel-pppd
177181
main.c
178182
)
179183

180-
IF (HAVE_VPP)
184+
IF (HAVE_SESSION_HOOKS)
181185
TARGET_SOURCES(accel-pppd PRIVATE
182-
vpputils/vpputils.c
183-
vpputils/vpppoe.c
184-
vpputils/vppiputils.c
185-
vpputils/vppipv6layer.c
186-
vpputils/vpppolicer.c
187-
)
188-
189-
TARGET_LINK_LIBRARIES(accel-pppd vapiclient vlibapi vlib)
190-
endif(HAVE_VPP)
186+
ap_session_hooks.c)
187+
ADD_SUBDIRECTORY(session_hooks)
188+
ENDIF (HAVE_SESSION_HOOKS)
191189

192190
# check if we have getcontext/setcontext
193191
INCLUDE(CheckFunctionExists)

accel-pppd/accel_iputils.c

Lines changed: 44 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -6,169 +6,117 @@
66

77
#include "ap_session.h"
88
#include "iputils.h"
9-
#include "vppiputils.h"
109

1110
#include "accel_iputils.h"
1211

1312
/* TODO: refactore & redesign */
1413

1514
__export int accel_ipaddr_add(struct ap_session *ses, int ifindex, in_addr_t addr, int mask)
1615
{
17-
#ifdef HAVE_VPP
18-
if (ses->non_dev_ppp_fixup != NULL)
19-
{
20-
/* setup route instead */
21-
return vpp_iproute_add_del(ses, 1, ses->vpp_sw_if_index, 0, addr, 0, 0, mask, 0);
22-
}
16+
#ifdef HAVE_SESSION_HOOKS
17+
if (ses->hooks && ses->hooks->ipaddr_add)
18+
return ses->hooks->ipaddr_add(ses, ifindex, addr, mask);
2319
else
24-
#endif
25-
{
20+
#endif /* HAVE_SESSION_HOOKS */
2621
return ipaddr_add(ifindex, addr, mask);
27-
}
2822
}
2923

3024
__export int accel_ipaddr_add_peer(struct ap_session *ses, int ifindex, in_addr_t addr, in_addr_t peer_addr)
3125
{
32-
#ifdef HAVE_VPP
33-
if (ses->non_dev_ppp_fixup != NULL)
34-
{
35-
/* setup route instead */
36-
return vpp_iproute_add_del(ses, 1, ses->vpp_sw_if_index, 0, peer_addr, 0, 0, 32, 0);
37-
}
26+
#ifdef HAVE_SESSION_HOOKS
27+
if (ses->hooks && ses->hooks->ipaddr_add_peer)
28+
return ses->hooks->ipaddr_add_peer(ses, ifindex, addr, peer_addr);
3829
else
39-
#endif
40-
{
30+
#endif /* HAVE_SESSION_HOOKS */
4131
return ipaddr_add_peer(ifindex, addr, peer_addr);
42-
}
4332
}
4433

4534
__export int accel_ipaddr_del(struct ap_session *ses, int ifindex, in_addr_t addr, int mask)
4635
{
47-
#ifdef HAVE_VPP
48-
if (ses->non_dev_ppp_fixup != NULL)
49-
{
50-
/* remove route instead */
51-
return vpp_iproute_add_del(ses, 0, ses->vpp_sw_if_index, 0, addr, 0, 0, mask, 0);
52-
}
36+
#ifdef HAVE_SESSION_HOOKS
37+
if (ses->hooks && ses->hooks->ipaddr_del)
38+
return ses->hooks->ipaddr_del(ses, ifindex, addr, mask);
5339
else
54-
#endif
55-
{
40+
#endif /* HAVE_SESSION_HOOKS */
5641
return ipaddr_del(ifindex, addr, mask);
57-
}
5842
}
5943

6044
__export int accel_ipaddr_del_peer(struct ap_session *ses, int ifindex, in_addr_t addr, in_addr_t peer)
6145
{
62-
#ifdef HAVE_VPP
63-
if (ses->non_dev_ppp_fixup != NULL)
64-
{
65-
/* remove route instead */
66-
return vpp_iproute_add_del(ses, 0, ses->vpp_sw_if_index, 0, peer, 0, 0, 32, 0);
67-
}
46+
#ifdef HAVE_SESSION_HOOKS
47+
if (ses->hooks && ses->hooks->ipaddr_del_peer)
48+
return ses->hooks->ipaddr_del_peer(ses, ifindex, addr, peer);
6849
else
69-
#endif
70-
{
50+
#endif /* HAVE_SESSION_HOOKS */
7151
return ipaddr_del_peer(ifindex, addr, peer);
72-
}
7352
}
7453

7554
__export int accel_iproute_add(struct ap_session *ses, int ifindex, in_addr_t src, in_addr_t dst, in_addr_t gw, int proto, int mask, uint32_t prio, const char *vrf_name)
7655
{
77-
#ifdef HAVE_VPP
78-
if (ses->non_dev_ppp_fixup != NULL)
79-
{
80-
return vpp_iproute_add_del(ses, 1, ses->vpp_sw_if_index, src, dst, gw, proto, mask, prio);
81-
}
56+
#ifdef HAVE_SESSION_HOOKS
57+
if (ses->hooks && ses->hooks->iproute_add)
58+
return ses->hooks->iproute_add(ses, ifindex, src, dst, gw, proto, mask, prio, vrf_name);
8259
else
83-
#endif
84-
{
60+
#endif /* HAVE_SESSION_HOOKS */
8561
return iproute_add(ifindex, src, dst, gw, proto, mask, prio, vrf_name);
86-
}
8762
}
8863

8964
__export int accel_iproute_del(struct ap_session *ses, int ifindex, in_addr_t src, in_addr_t dst, in_addr_t gw, int proto, int mask, uint32_t prio, const char *vrf_name)
9065
{
91-
#ifdef HAVE_VPP
92-
if (ses->non_dev_ppp_fixup != NULL)
93-
{
94-
return vpp_iproute_add_del(ses, 0, ses->vpp_sw_if_index, src, dst, gw, proto, mask, prio);
95-
}
66+
#ifdef HAVE_SESSION_HOOKS
67+
if (ses->hooks && ses->hooks->iproute_del)
68+
return ses->hooks->iproute_del(ses, ifindex, src, dst, gw, proto, mask, prio, vrf_name);
9669
else
97-
#endif
98-
{
70+
#endif /* HAVE_SESSION_HOOKS */
9971
return iproute_del(ifindex, src, dst, gw, proto, mask, prio, vrf_name);
100-
}
10172
}
10273

10374
__export int accel_ip6route_add(struct ap_session *ses, int ifindex, const struct in6_addr *dst, int pref_len, const struct in6_addr *gw, int proto, uint32_t prio, const char *vrf_name)
10475
{
105-
#ifdef HAVE_VPP
106-
if (ses->non_dev_ppp_fixup != NULL)
107-
{
108-
return vpp_ip6route_add_del(ses, 1, ses->vpp_sw_if_index, dst, pref_len, gw, proto, prio);
109-
}
76+
#ifdef HAVE_SESSION_HOOKS
77+
if (ses->hooks && ses->hooks->ip6route_add)
78+
return ses->hooks->ip6route_add(ses, ifindex, dst, pref_len, gw, proto, prio, vrf_name);
11079
else
111-
#endif
112-
{
80+
#endif /* HAVE_SESSION_HOOKS */
11381
return ip6route_add(ifindex, dst, pref_len, gw, proto, prio, vrf_name);
114-
}
11582
}
11683

11784
__export int accel_ip6route_del(struct ap_session *ses, int ifindex, const struct in6_addr *dst, int pref_len, const struct in6_addr *gw, int proto, uint32_t prio, const char *vrf_name)
11885
{
119-
#ifdef HAVE_VPP
120-
if (ses->non_dev_ppp_fixup != NULL)
121-
{
122-
return vpp_ip6route_add_del(ses, 0, ses->vpp_sw_if_index, dst, pref_len, gw, proto, prio);
123-
}
86+
#ifdef HAVE_SESSION_HOOKS
87+
if (ses->hooks && ses->hooks->ip6route_del)
88+
return ses->hooks->ip6route_del(ses, ifindex, dst, pref_len, gw, proto, prio, vrf_name);
12489
else
125-
#endif
126-
{
90+
#endif /* HAVE_SESSION_HOOKS */
12791
return ip6route_del(ifindex, dst, pref_len, gw, proto, prio, vrf_name);
128-
}
12992
}
13093

13194
__export int accel_ip6addr_add(struct ap_session *ses, int ifindex, struct in6_addr *addr, int prefix_len)
13295
{
133-
#ifdef HAVE_VPP
134-
if (ses->non_dev_ppp_fixup != NULL)
135-
{
136-
/* setup route instead */
137-
return vpp_ip6route_add_del(ses, 1, ses->vpp_sw_if_index, addr, prefix_len, NULL, 0, 0);
138-
}
96+
#ifdef HAVE_SESSION_HOOKS
97+
if (ses->hooks && ses->hooks->ip6addr_add)
98+
return ses->hooks->ip6addr_add(ses, ifindex, addr, prefix_len);
13999
else
140-
#endif
141-
{
100+
#endif /* HAVE_SESSION_HOOKS */
142101
return ip6addr_add(ifindex, addr, prefix_len);
143-
}
144102
}
145103

146104
__export int accel_ip6addr_add_peer(struct ap_session *ses, int ifindex, struct in6_addr *addr, struct in6_addr *peer_addr)
147105
{
148-
#ifdef HAVE_VPP
149-
if (ses->non_dev_ppp_fixup != NULL)
150-
{
151-
/* setup route instead */
152-
return vpp_ip6route_add_del(ses, 1, ses->vpp_sw_if_index, peer_addr, 128, NULL, 0, 0);
153-
}
106+
#ifdef HAVE_SESSION_HOOKS
107+
if (ses->hooks && ses->hooks->ip6addr_add_peer)
108+
return ses->hooks->ip6addr_add_peer(ses, ifindex, addr, peer_addr);
154109
else
155-
#endif
156-
{
110+
#endif /* HAVE_SESSION_HOOKS */
157111
return ip6addr_add_peer(ifindex, addr, peer_addr);
158-
}
159112
}
160113

161114
__export int accel_ip6addr_del(struct ap_session *ses, int ifindex, struct in6_addr *addr, int prefix_len)
162115
{
163-
#ifdef HAVE_VPP
164-
if (ses->non_dev_ppp_fixup != NULL)
165-
{
166-
/* remove route instead */
167-
return vpp_ip6route_add_del(ses, 0, ses->vpp_sw_if_index, addr, prefix_len, NULL, 0, 0);
168-
}
116+
#ifdef HAVE_SESSION_HOOKS
117+
if (ses->hooks && ses->hooks->ip6addr_del)
118+
return ses->hooks->ip6addr_del(ses, ifindex, addr, prefix_len);
169119
else
170-
#endif
171-
{
120+
#endif /* HAVE_SESSION_HOOKS */
172121
return ip6addr_del(ifindex, addr, prefix_len);
173-
}
174122
}

accel-pppd/ap_session_hooks.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
/*
3+
* Copyright (c) 2025 by VyOS Networks
4+
* Andrii Melnychenko a.melnychenko@vyos.io
5+
*/
6+
7+
#include <stddef.h>
8+
#include <string.h>
9+
10+
#include "triton.h"
11+
12+
#include "ap_session_hooks.h"
13+
14+
LIST_HEAD(ap_session_hooks_list);
15+
16+
__export
17+
int ap_session_hooks_register(struct ap_session_hooks_t *h)
18+
{
19+
if (h == NULL || h->hooks_name == NULL)
20+
return -1;
21+
22+
list_add_tail(&h->entry, &ap_session_hooks_list);
23+
return 0;
24+
}
25+
26+
__export
27+
void ap_session_hooks_unregister(struct ap_session_hooks_t *h)
28+
{
29+
if (h == NULL)
30+
return;
31+
32+
list_del(&h->entry);
33+
}
34+
35+
__export
36+
struct ap_session_hooks_t * ap_session_hooks_find(const char *name)
37+
{
38+
if (name == NULL)
39+
return NULL;
40+
41+
struct ap_session_hooks_t *h = NULL;
42+
list_for_each_entry(h, &ap_session_hooks_list, entry) {
43+
if (!strcmp(name, h->hooks_name))
44+
return h;
45+
}
46+
47+
return NULL;
48+
}

0 commit comments

Comments
 (0)