return 0;
}
+/**
+ * Clear the bits outside of the prefix length of an address
+ * @param dst trucated destination buffer
+ * @param src source IP
+ */
+void
+netaddr_truncate(struct netaddr *dst, const struct netaddr *src) {
+ static uint8_t MASK[] = { 0, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe };
+ int byte_prefix, bit_prefix;
+
+ /* calulate byte/bit part of prefix */
+ byte_prefix = src->_prefix_len / 8;
+ bit_prefix = src->_prefix_len & 7;
+
+ if (src != dst) {
+ /* copy type and prefix length */
+ dst->_prefix_len = src->_prefix_len;
+ dst->_type = src->_type;
+
+ /* copy constant octets */
+ memcpy(dst->_addr, src->_addr, byte_prefix);
+ }
+
+ if (bit_prefix) {
+ /* modify bitwise */
+ dst->_addr[byte_prefix] = src->_addr[byte_prefix] & MASK[bit_prefix];
+ byte_prefix++;
+ }
+
+ if (byte_prefix < 16) {
+ /* zero rest of address */
+ memset(&dst->_addr[byte_prefix], 0, 16 - byte_prefix);
+ }
+}
+
/**
* Initialize a netaddr_socket with a netaddr and a port number
* @param combined pointer to netaddr_socket to be initialized
const void *number, size_t num_length);
EXPORT int netaddr_create_prefix(struct netaddr *prefix, const struct netaddr *host,
const struct netaddr *netmask, bool truncate);
+EXPORT void netaddr_truncate(struct netaddr *dst, const struct netaddr *src);
EXPORT int netaddr_socket_init(union netaddr_socket *combined,
const struct netaddr *addr, uint16_t port, unsigned if_index);
if (netaddr_from_string(&prefix, addr_buf.buf)) {
continue;
}
+
+ /* truncate address */
+ netaddr_truncate(&prefix, &prefix);
+
if (_parse_lan_parameters(&data, ptr)) {
continue;
}
uint32_t cost_in[NHDP_MAXIMUM_DOMAINS];
uint32_t cost_out[NHDP_MAXIMUM_DOMAINS];
struct rfc7181_metric_field metric_value;
+ struct netaddr truncated;
size_t i;
#ifdef OONF_LOG_DEBUG_INFO
struct netaddr_str buf;
continue;
}
+ /* truncate address */
+ netaddr_truncate(&truncated, &context->addr);
+
/* parse attached network */
- end = olsrv2_tc_endpoint_add(_current.node, &context->addr, false);
+ end = olsrv2_tc_endpoint_add(_current.node, &truncated, false);
if (!end) {
continue;
}
static void
_remove_entry(struct olsrv2_routing_entry *entry) {
/* remove entry from database if its still there */
- if (list_is_node_added(&entry->_node.list)) {
+ if (avl_is_node_added(&entry->_node)) {
avl_remove(&_routing_tree[entry->domain->index], &entry->_node);
}
oonf_class_free(&_rtset_entry, entry);
strerror(error), error);
}
+ if (error == EEXIST && rtentry->set) {
+ /* exactly this route already exists */
+ return;
+ }
+
/* revert attempted change */
if (rtentry->set) {
_remove_entry(rtentry);