1
0
mirror of https://git.openwrt.org/feed/routing.git synced 2024-06-26 01:27:29 +02:00
openwrt-routing/babeld/src/ubus.h

93 lines
2.4 KiB
C
Raw Normal View History

babeld: add ubus bindings A better integration of babeld with OpenWrt is to connect the daemon to the IPC. So far, we can only communicate via a websocket. With ubus we can send and receive commands in json format. The commit adds a ubus interface to babeld with following functions: - get_info - get_neighbours - get_xroutes - get_routes All output is divided into IPv4 and IPv6. Ubus has to be enabled by setting "config general" option 'ubus_bindings' 'true' Example: root@OpenWrt:~# ubus call babeld get_info { "babeld-version": "babeld-1.9.2", "my-id": "32:xx:xx:xx:xx:xx:xx:xx", "host": "OpenWrt" } root@OpenWrt:~# ubus call babeld get_neighbours { "IPv4": { }, "IPv6": { "fe80::xx:xx:xx:xxx": { "dev": "br-lan", "hello-reach": 65408, "uhello-reach": 0, "rxcost": 96, "txcost": 96, "rtt": 4338271, "channel": -2, "if_up": true } } } root@OpenWrt:~# ubus call babeld get_xroutes { "IPv4": { "10.0.0.3/32": { "src-prefix": "0.0.0.0/0", "metric": 0 }, "10.0.0.0/24": { "src-prefix": "0.0.0.0/0", "metric": 0 } }, "IPv6": { "fdfa:xx:xx::1/128": { "src-prefix": "::/0", "metric": 0 } } } root@OpenWrt:~# ubus call babeld get_routes { "IPv4": { "10.2.0.1/32": { "src-prefix": "0.0.0.0/0", "route_metric": 96, "route_smoothed_metric": 96, "refmetric": 0, "id": "62:xx:xx:xx:xx:xx:xx:xx", "seqno": 41381, "channels": "", "age": 17, "via": "fe80::xx:xxxx:xxxx:xxxx", "nexthop": " nexthop ", "installed": true, "feasible": true }, "IPv6": { } } Additional IPC functionality will follow. Further, we changed the version to $version-ubus-mod. Signed-off-by: Nick Hainke <vincent@systemli.org>
2020-12-17 12:41:32 +01:00
/*
IPC integration of babeld with OpenWrt.
babeld: add ubus bindings A better integration of babeld with OpenWrt is to connect the daemon to the IPC. So far, we can only communicate via a websocket. With ubus we can send and receive commands in json format. The commit adds a ubus interface to babeld with following functions: - get_info - get_neighbours - get_xroutes - get_routes All output is divided into IPv4 and IPv6. Ubus has to be enabled by setting "config general" option 'ubus_bindings' 'true' Example: root@OpenWrt:~# ubus call babeld get_info { "babeld-version": "babeld-1.9.2", "my-id": "32:xx:xx:xx:xx:xx:xx:xx", "host": "OpenWrt" } root@OpenWrt:~# ubus call babeld get_neighbours { "IPv4": { }, "IPv6": { "fe80::xx:xx:xx:xxx": { "dev": "br-lan", "hello-reach": 65408, "uhello-reach": 0, "rxcost": 96, "txcost": 96, "rtt": 4338271, "channel": -2, "if_up": true } } } root@OpenWrt:~# ubus call babeld get_xroutes { "IPv4": { "10.0.0.3/32": { "src-prefix": "0.0.0.0/0", "metric": 0 }, "10.0.0.0/24": { "src-prefix": "0.0.0.0/0", "metric": 0 } }, "IPv6": { "fdfa:xx:xx::1/128": { "src-prefix": "::/0", "metric": 0 } } } root@OpenWrt:~# ubus call babeld get_routes { "IPv4": { "10.2.0.1/32": { "src-prefix": "0.0.0.0/0", "route_metric": 96, "route_smoothed_metric": 96, "refmetric": 0, "id": "62:xx:xx:xx:xx:xx:xx:xx", "seqno": 41381, "channels": "", "age": 17, "via": "fe80::xx:xxxx:xxxx:xxxx", "nexthop": " nexthop ", "installed": true, "feasible": true }, "IPv6": { } } Additional IPC functionality will follow. Further, we changed the version to $version-ubus-mod. Signed-off-by: Nick Hainke <vincent@systemli.org>
2020-12-17 12:41:32 +01:00
The ubus interface offers following functions:
- get_info
- get_neighbours
- get_xroutes
- get_routes
babeld: add ubus bindings A better integration of babeld with OpenWrt is to connect the daemon to the IPC. So far, we can only communicate via a websocket. With ubus we can send and receive commands in json format. The commit adds a ubus interface to babeld with following functions: - get_info - get_neighbours - get_xroutes - get_routes All output is divided into IPv4 and IPv6. Ubus has to be enabled by setting "config general" option 'ubus_bindings' 'true' Example: root@OpenWrt:~# ubus call babeld get_info { "babeld-version": "babeld-1.9.2", "my-id": "32:xx:xx:xx:xx:xx:xx:xx", "host": "OpenWrt" } root@OpenWrt:~# ubus call babeld get_neighbours { "IPv4": { }, "IPv6": { "fe80::xx:xx:xx:xxx": { "dev": "br-lan", "hello-reach": 65408, "uhello-reach": 0, "rxcost": 96, "txcost": 96, "rtt": 4338271, "channel": -2, "if_up": true } } } root@OpenWrt:~# ubus call babeld get_xroutes { "IPv4": { "10.0.0.3/32": { "src-prefix": "0.0.0.0/0", "metric": 0 }, "10.0.0.0/24": { "src-prefix": "0.0.0.0/0", "metric": 0 } }, "IPv6": { "fdfa:xx:xx::1/128": { "src-prefix": "::/0", "metric": 0 } } } root@OpenWrt:~# ubus call babeld get_routes { "IPv4": { "10.2.0.1/32": { "src-prefix": "0.0.0.0/0", "route_metric": 96, "route_smoothed_metric": 96, "refmetric": 0, "id": "62:xx:xx:xx:xx:xx:xx:xx", "seqno": 41381, "channels": "", "age": 17, "via": "fe80::xx:xxxx:xxxx:xxxx", "nexthop": " nexthop ", "installed": true, "feasible": true }, "IPv6": { } } Additional IPC functionality will follow. Further, we changed the version to $version-ubus-mod. Signed-off-by: Nick Hainke <vincent@systemli.org>
2020-12-17 12:41:32 +01:00
All output is divided into IPv4 and IPv6.
Ubus notifications are sent if we receive updates for
- xroutes
- routes
- neighbours
The format is:
- {route,xroute,neighbour}.add: Object was added
- {route,xroute,neighbour}.change: Object was changed
- {route,xroute,neighbour}.flush: Object was flushed
babeld: add ubus bindings A better integration of babeld with OpenWrt is to connect the daemon to the IPC. So far, we can only communicate via a websocket. With ubus we can send and receive commands in json format. The commit adds a ubus interface to babeld with following functions: - get_info - get_neighbours - get_xroutes - get_routes All output is divided into IPv4 and IPv6. Ubus has to be enabled by setting "config general" option 'ubus_bindings' 'true' Example: root@OpenWrt:~# ubus call babeld get_info { "babeld-version": "babeld-1.9.2", "my-id": "32:xx:xx:xx:xx:xx:xx:xx", "host": "OpenWrt" } root@OpenWrt:~# ubus call babeld get_neighbours { "IPv4": { }, "IPv6": { "fe80::xx:xx:xx:xxx": { "dev": "br-lan", "hello-reach": 65408, "uhello-reach": 0, "rxcost": 96, "txcost": 96, "rtt": 4338271, "channel": -2, "if_up": true } } } root@OpenWrt:~# ubus call babeld get_xroutes { "IPv4": { "10.0.0.3/32": { "src-prefix": "0.0.0.0/0", "metric": 0 }, "10.0.0.0/24": { "src-prefix": "0.0.0.0/0", "metric": 0 } }, "IPv6": { "fdfa:xx:xx::1/128": { "src-prefix": "::/0", "metric": 0 } } } root@OpenWrt:~# ubus call babeld get_routes { "IPv4": { "10.2.0.1/32": { "src-prefix": "0.0.0.0/0", "route_metric": 96, "route_smoothed_metric": 96, "refmetric": 0, "id": "62:xx:xx:xx:xx:xx:xx:xx", "seqno": 41381, "channels": "", "age": 17, "via": "fe80::xx:xxxx:xxxx:xxxx", "nexthop": " nexthop ", "installed": true, "feasible": true }, "IPv6": { } } Additional IPC functionality will follow. Further, we changed the version to $version-ubus-mod. Signed-off-by: Nick Hainke <vincent@systemli.org>
2020-12-17 12:41:32 +01:00
*/
#include <stdbool.h>
#include <sys/select.h>
struct babel_route;
struct neighbour;
struct xroute;
babeld: add ubus bindings A better integration of babeld with OpenWrt is to connect the daemon to the IPC. So far, we can only communicate via a websocket. With ubus we can send and receive commands in json format. The commit adds a ubus interface to babeld with following functions: - get_info - get_neighbours - get_xroutes - get_routes All output is divided into IPv4 and IPv6. Ubus has to be enabled by setting "config general" option 'ubus_bindings' 'true' Example: root@OpenWrt:~# ubus call babeld get_info { "babeld-version": "babeld-1.9.2", "my-id": "32:xx:xx:xx:xx:xx:xx:xx", "host": "OpenWrt" } root@OpenWrt:~# ubus call babeld get_neighbours { "IPv4": { }, "IPv6": { "fe80::xx:xx:xx:xxx": { "dev": "br-lan", "hello-reach": 65408, "uhello-reach": 0, "rxcost": 96, "txcost": 96, "rtt": 4338271, "channel": -2, "if_up": true } } } root@OpenWrt:~# ubus call babeld get_xroutes { "IPv4": { "10.0.0.3/32": { "src-prefix": "0.0.0.0/0", "metric": 0 }, "10.0.0.0/24": { "src-prefix": "0.0.0.0/0", "metric": 0 } }, "IPv6": { "fdfa:xx:xx::1/128": { "src-prefix": "::/0", "metric": 0 } } } root@OpenWrt:~# ubus call babeld get_routes { "IPv4": { "10.2.0.1/32": { "src-prefix": "0.0.0.0/0", "route_metric": 96, "route_smoothed_metric": 96, "refmetric": 0, "id": "62:xx:xx:xx:xx:xx:xx:xx", "seqno": 41381, "channels": "", "age": 17, "via": "fe80::xx:xxxx:xxxx:xxxx", "nexthop": " nexthop ", "installed": true, "feasible": true }, "IPv6": { } } Additional IPC functionality will follow. Further, we changed the version to $version-ubus-mod. Signed-off-by: Nick Hainke <vincent@systemli.org>
2020-12-17 12:41:32 +01:00
// Whether to enable ubus bindings (boolean option).
extern int ubus_bindings;
/**
* Initialize ubus interface.
*
* Connect to the ubus daemon and expose the ubus functions.
*
* @return if initializing ubus was successful
*/
bool babeld_add_ubus();
/**
* Add ubus socket to given filedescriptor set.
*
* We need to check repeatedly if the ubus socket has something to read.
* The functions allows to add the ubus socket to the normal while(1)-loop of
* babeld.
babeld: add ubus bindings A better integration of babeld with OpenWrt is to connect the daemon to the IPC. So far, we can only communicate via a websocket. With ubus we can send and receive commands in json format. The commit adds a ubus interface to babeld with following functions: - get_info - get_neighbours - get_xroutes - get_routes All output is divided into IPv4 and IPv6. Ubus has to be enabled by setting "config general" option 'ubus_bindings' 'true' Example: root@OpenWrt:~# ubus call babeld get_info { "babeld-version": "babeld-1.9.2", "my-id": "32:xx:xx:xx:xx:xx:xx:xx", "host": "OpenWrt" } root@OpenWrt:~# ubus call babeld get_neighbours { "IPv4": { }, "IPv6": { "fe80::xx:xx:xx:xxx": { "dev": "br-lan", "hello-reach": 65408, "uhello-reach": 0, "rxcost": 96, "txcost": 96, "rtt": 4338271, "channel": -2, "if_up": true } } } root@OpenWrt:~# ubus call babeld get_xroutes { "IPv4": { "10.0.0.3/32": { "src-prefix": "0.0.0.0/0", "metric": 0 }, "10.0.0.0/24": { "src-prefix": "0.0.0.0/0", "metric": 0 } }, "IPv6": { "fdfa:xx:xx::1/128": { "src-prefix": "::/0", "metric": 0 } } } root@OpenWrt:~# ubus call babeld get_routes { "IPv4": { "10.2.0.1/32": { "src-prefix": "0.0.0.0/0", "route_metric": 96, "route_smoothed_metric": 96, "refmetric": 0, "id": "62:xx:xx:xx:xx:xx:xx:xx", "seqno": 41381, "channels": "", "age": 17, "via": "fe80::xx:xxxx:xxxx:xxxx", "nexthop": " nexthop ", "installed": true, "feasible": true }, "IPv6": { } } Additional IPC functionality will follow. Further, we changed the version to $version-ubus-mod. Signed-off-by: Nick Hainke <vincent@systemli.org>
2020-12-17 12:41:32 +01:00
*
* @param readfs: the filedescriptor set
* @param maxfd: the current maximum file descriptor
* @return the maximum file descriptor
*/
int babeld_ubus_add_read_sock(fd_set *readfds, int maxfd);
babeld: add ubus bindings A better integration of babeld with OpenWrt is to connect the daemon to the IPC. So far, we can only communicate via a websocket. With ubus we can send and receive commands in json format. The commit adds a ubus interface to babeld with following functions: - get_info - get_neighbours - get_xroutes - get_routes All output is divided into IPv4 and IPv6. Ubus has to be enabled by setting "config general" option 'ubus_bindings' 'true' Example: root@OpenWrt:~# ubus call babeld get_info { "babeld-version": "babeld-1.9.2", "my-id": "32:xx:xx:xx:xx:xx:xx:xx", "host": "OpenWrt" } root@OpenWrt:~# ubus call babeld get_neighbours { "IPv4": { }, "IPv6": { "fe80::xx:xx:xx:xxx": { "dev": "br-lan", "hello-reach": 65408, "uhello-reach": 0, "rxcost": 96, "txcost": 96, "rtt": 4338271, "channel": -2, "if_up": true } } } root@OpenWrt:~# ubus call babeld get_xroutes { "IPv4": { "10.0.0.3/32": { "src-prefix": "0.0.0.0/0", "metric": 0 }, "10.0.0.0/24": { "src-prefix": "0.0.0.0/0", "metric": 0 } }, "IPv6": { "fdfa:xx:xx::1/128": { "src-prefix": "::/0", "metric": 0 } } } root@OpenWrt:~# ubus call babeld get_routes { "IPv4": { "10.2.0.1/32": { "src-prefix": "0.0.0.0/0", "route_metric": 96, "route_smoothed_metric": 96, "refmetric": 0, "id": "62:xx:xx:xx:xx:xx:xx:xx", "seqno": 41381, "channels": "", "age": 17, "via": "fe80::xx:xxxx:xxxx:xxxx", "nexthop": " nexthop ", "installed": true, "feasible": true }, "IPv6": { } } Additional IPC functionality will follow. Further, we changed the version to $version-ubus-mod. Signed-off-by: Nick Hainke <vincent@systemli.org>
2020-12-17 12:41:32 +01:00
/**
* Check and process ubus socket.
*
* If the ubus-socket signals that data is available, the ubus_handle_event is
* called.
*/
void babeld_ubus_receive(fd_set *readfds);
/***
* Notify the ubus bus that a new xroute is received.
*
* If a new xroute is received or changed, we will notify subscribers.
*
* @param xroute: xroute that experienced some change
* @param kind: kind that describes if we have a flush, add or change
*/
void ubus_notify_xroute(struct xroute *xroute, int kind);
/***
* Notify the ubus bus that a new route is received.
*
* If a new route is received or changed, we will notify subscribers.
*
* @param route: route that experienced some change
* @param kind: kind that describes if we have a flush, add or change
*/
void ubus_notify_route(struct babel_route *route, int kind);
/***
* Notify the ubus bus that a new neighbour is received.
*
* If a new neighbour is received or changed, we will notify subscribers.
*
* @param neigh: neighbour that experienced some change
* @param kind: kind that describes if we have a flush, add or change
babeld: add ubus bindings A better integration of babeld with OpenWrt is to connect the daemon to the IPC. So far, we can only communicate via a websocket. With ubus we can send and receive commands in json format. The commit adds a ubus interface to babeld with following functions: - get_info - get_neighbours - get_xroutes - get_routes All output is divided into IPv4 and IPv6. Ubus has to be enabled by setting "config general" option 'ubus_bindings' 'true' Example: root@OpenWrt:~# ubus call babeld get_info { "babeld-version": "babeld-1.9.2", "my-id": "32:xx:xx:xx:xx:xx:xx:xx", "host": "OpenWrt" } root@OpenWrt:~# ubus call babeld get_neighbours { "IPv4": { }, "IPv6": { "fe80::xx:xx:xx:xxx": { "dev": "br-lan", "hello-reach": 65408, "uhello-reach": 0, "rxcost": 96, "txcost": 96, "rtt": 4338271, "channel": -2, "if_up": true } } } root@OpenWrt:~# ubus call babeld get_xroutes { "IPv4": { "10.0.0.3/32": { "src-prefix": "0.0.0.0/0", "metric": 0 }, "10.0.0.0/24": { "src-prefix": "0.0.0.0/0", "metric": 0 } }, "IPv6": { "fdfa:xx:xx::1/128": { "src-prefix": "::/0", "metric": 0 } } } root@OpenWrt:~# ubus call babeld get_routes { "IPv4": { "10.2.0.1/32": { "src-prefix": "0.0.0.0/0", "route_metric": 96, "route_smoothed_metric": 96, "refmetric": 0, "id": "62:xx:xx:xx:xx:xx:xx:xx", "seqno": 41381, "channels": "", "age": 17, "via": "fe80::xx:xxxx:xxxx:xxxx", "nexthop": " nexthop ", "installed": true, "feasible": true }, "IPv6": { } } Additional IPC functionality will follow. Further, we changed the version to $version-ubus-mod. Signed-off-by: Nick Hainke <vincent@systemli.org>
2020-12-17 12:41:32 +01:00
*/
void ubus_notify_neighbour(struct neighbour *neigh, int kind);