-
Notifications
You must be signed in to change notification settings - Fork 451
babeld: send events via ubus #633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,7 +87,8 @@ static void babeld_add_xroute_buf(struct xroute *xroute, struct blob_buf *b) { | |
| blobmsg_close_table(b, prefix); | ||
| } | ||
|
|
||
| // Sends an exported routes message on ubus socket, splitting apart IPv4 and IPv6 routes. | ||
| // Sends an exported routes message on ubus socket, splitting apart IPv4 and | ||
| // IPv6 routes. | ||
| static void babeld_ubus_get_xroutes(struct ubus_context *ctx_local, | ||
| struct ubus_object *obj, | ||
| struct ubus_request_data *req, | ||
|
|
@@ -187,7 +188,8 @@ static void babeld_add_route_buf(struct babel_route *route, | |
| blobmsg_close_table(b, prefix); | ||
| } | ||
|
|
||
| // Sends received routes message on ubus socket, splitting apart IPv4 and IPv6 routes. | ||
| // Sends received routes message on ubus socket, splitting apart IPv4 and IPv6 | ||
| // routes. | ||
| static void babeld_ubus_get_routes(struct ubus_context *ctx_local, | ||
| struct ubus_object *obj, | ||
| struct ubus_request_data *req, | ||
|
|
@@ -259,7 +261,8 @@ static void babeld_add_neighbour_buf(struct neighbour *neigh, | |
| blobmsg_close_table(b, neighbour); | ||
| } | ||
|
|
||
| // Sends neighbours message on ubus socket, splitting apart IPv4 and IPv6 neighbours. | ||
| // Sends neighbours message on ubus socket, splitting apart IPv4 and IPv6 | ||
| // neighbours. | ||
| static void babeld_ubus_get_neighbours(struct ubus_context *ctx_local, | ||
| struct ubus_object *obj, | ||
| struct ubus_request_data *req, | ||
|
|
@@ -342,7 +345,8 @@ static bool ubus_init_object() { | |
| return true; | ||
| } | ||
|
|
||
| // Initializes the global ubus context, connecting to the bus to be able to receive and send messages. | ||
| // Initializes the global ubus context, connecting to the bus to be able to | ||
| // receive and send messages. | ||
| static bool babeld_ubus_init(void) { | ||
| if (shared_ctx) | ||
| return true; | ||
|
|
@@ -354,6 +358,63 @@ static bool babeld_ubus_init(void) { | |
| return true; | ||
| } | ||
|
|
||
| void ubus_notify_route(struct babel_route *route, int kind) { | ||
| struct blob_buf b = {0}; | ||
| char method[13]; // max is route.change | ||
|
|
||
| if (!babeld_object.has_subscribers) | ||
| return; | ||
|
|
||
| if (!route) | ||
| return; | ||
|
|
||
| if (!shared_ctx) | ||
| return; | ||
|
|
||
| blob_buf_init(&b, 0); | ||
| babeld_add_route_buf(route, &b); | ||
| sprintf(method, "route.%s", local_kind(kind)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use snprintf(method, sizeof(method), ...), I'm paranoid about buffer overflow. Idem below.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True story. :) |
||
| ubus_notify(shared_ctx, &babeld_object, method, b.head, -1); | ||
| } | ||
|
|
||
| void ubus_notify_xroute(struct xroute *xroute, int kind) { | ||
| struct blob_buf b = {0}; | ||
| char method[14]; // max is xroute.change | ||
|
|
||
| if (!babeld_object.has_subscribers) | ||
| return; | ||
|
|
||
| if (!xroute) | ||
| return; | ||
|
|
||
| if (!shared_ctx) | ||
| return; | ||
|
|
||
| blob_buf_init(&b, 0); | ||
| babeld_add_xroute_buf(xroute, &b); | ||
| sprintf(method, "xroute.%s", local_kind(kind)); | ||
| ubus_notify(shared_ctx, &babeld_object, method, b.head, -1); | ||
| } | ||
|
|
||
| void ubus_notify_neighbour(struct neighbour *neigh, int kind) { | ||
| struct blob_buf b = {0}; | ||
| char method[13]; // max is neigh.change | ||
|
|
||
| if (!babeld_object.has_subscribers) | ||
| return; | ||
|
|
||
| if (!neigh) | ||
| return; | ||
|
|
||
| if (!shared_ctx) | ||
| return; | ||
|
|
||
| blob_buf_init(&b, 0); | ||
| babeld_add_neighbour_buf(neigh, &b); | ||
| sprintf(method, "neigh.%s", local_kind(kind)); | ||
| ubus_notify(shared_ctx, &babeld_object, method, b.head, -1); | ||
| } | ||
|
|
||
| void babeld_ubus_receive(fd_set *readfds) { | ||
| if (!shared_ctx) | ||
| return; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
char method[sizeof("route.change")]; // possible methods are route.change, route.add, route.flush
Idem below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or just use a largish value and don't bother (50, 100)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will just go for 50. ;)