3 * The olsr.org Optimized Link-State Routing daemon(olsrd)
4 * Copyright (c) 2005, Andreas Tonnesen(andreto@olsr.org)
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of olsr.org, olsrd nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
34 * Visit http://www.olsr.org for more information.
36 * If you find this software useful feel free to make a donation
37 * to the project. For more information see the website or contact
38 * the copyright holders.
42 #include "link_rules.h"
43 #include "olsr_host_switch.h"
45 #include "olsr_random.h"
52 ohs_check_link(struct ohs_connection *oc, union olsr_ip_addr *dst)
54 struct ohs_ip_link *links;
55 for (links = oc->links; links != NULL; links = links->next) {
57 if (!ipequal(&links->dst, dst)) {
60 if (links->quality == 0) {
61 if (logbits & LOG_LINK) {
62 struct ipaddr_str addrstr, dststr;
63 printf("%s -> %s Q: %d\n", olsr_ip_to_string(&addrstr, &oc->ip_addr), olsr_ip_to_string(&dststr, dst), links->quality);
68 r = 1 + (int)(100.0 / (RAND_MAX + 1.0) * olsr_random());
70 if (logbits & LOG_LINK) {
71 struct ipaddr_str addrstr, dststr;
72 printf("%s -> %s Q: %d R: %d\n", olsr_ip_to_string(&addrstr, &oc->ip_addr), olsr_ip_to_string(&dststr, dst), links->quality,
75 /* Random - based on quality */
76 return links->quality > r ? 0 : 1;
82 ohs_delete_all_related_links(struct ohs_connection *oc)
84 struct ohs_ip_link *links = oc->links;
87 /* Delete links from this node */
89 struct ohs_ip_link *tmp_link = links;
95 /* Delete links to this node */
103 add_link(struct ohs_connection *src, struct ohs_connection *dst)
105 struct ohs_ip_link *link;
107 /* Create new link */
108 link = malloc(sizeof(struct ohs_ip_link));
110 OHS_OUT_OF_MEMORY("New link");
112 link->next = src->links;
114 link->dst = dst->ip_addr;
121 remove_link(struct ohs_connection *oc, struct ohs_ip_link *lnk)
123 struct ohs_ip_link *links = oc->links;
124 struct ohs_ip_link *prev_link = NULL;
130 prev_link->next = links->next;
132 oc->links = links->next;
145 get_link(struct ohs_connection *oc, union olsr_ip_addr *dst)
147 struct ohs_ip_link *links;
148 for (links = oc->links; links != NULL; links = links->next) {
149 if (ipequal(&links->dst, dst)) {
159 * indent-tabs-mode: nil