2 * Author: Steven Barth <steven at midlink.org>
4 * Copyright 2015 Deutsche Telekom AG
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
22 #include <libubox/list.h>
23 #include <libubox/avl.h>
24 #include <libubox/uloop.h>
25 #include <arpa/inet.h>
31 struct list_head sources
;
33 omgp_time_t exclude_until
;
34 omgp_time_t compat_v2_until
;
35 omgp_time_t compat_v1_until
;
36 omgp_time_t next_generic_transmit
;
37 omgp_time_t next_source_transmit
;
42 struct list_head head
;
44 omgp_time_t include_until
;
48 struct groups_config
{
49 omgp_time_t query_response_interval
;
50 omgp_time_t query_interval
;
51 omgp_time_t last_listener_query_interval
;
53 int last_listener_query_count
;
57 struct groups_config cfg_v4
;
58 struct groups_config cfg_v6
;
59 struct avl_tree groups
;
60 struct uloop_timeout timer
;
63 void (*cb_query
)(struct groups
*g
, const struct in6_addr
*addr
,
64 const struct list_head
*sources
, bool suppress
);
65 void (*cb_update
)(struct groups
*g
, struct group
*group
, omgp_time_t now
);
69 void groups_init(struct groups
*groups
);
70 void groups_deinit(struct groups
*groups
);
75 UPDATE_IS_INCLUDE
= 1,
76 UPDATE_IS_EXCLUDE
= 2,
88 void groups_update_config(struct groups
*groups
, bool v6
,
89 omgp_time_t query_response_interval
, omgp_time_t query_interval
, int robustness
);
91 void groups_update_timers(struct groups
*groups
,
92 const struct in6_addr
*groupaddr
,
93 const struct in6_addr
*addrs
, size_t len
);
95 void groups_update_state(struct groups
*groups
,
96 const struct in6_addr
*groupaddr
,
97 const struct in6_addr
*addrs
, size_t len
,
98 enum groups_update update
);
100 void groups_synthesize_events(struct groups
*groups
);
102 // Groups user query API
104 static inline bool group_is_included(const struct group
*group
, omgp_time_t time
)
106 return group
->exclude_until
<= time
;
109 static inline bool source_is_included(const struct group_source
*source
, omgp_time_t time
)
111 return source
->include_until
> time
;
114 #define groups_for_each_group(group, groupsp) \
115 avl_for_each_element(&(groupsp)->groups, group, node)
117 #define group_for_each_source(source, group) \
118 list_for_each_entry(source, &(group)->sources, head)
120 #define group_for_each_active_source(source, group, time) \
121 list_for_each_entry(source, &group->sources, head) \
122 if (source_is_included(source, time) == group_is_included(group, time))
124 const struct group
* groups_get(struct groups
*groups
, const struct in6_addr
*addr
);
125 bool groups_includes_group(struct groups
*groups
, const struct in6_addr
*addr
,
126 const struct in6_addr
*src
, omgp_time_t time
);