3 Copyright (C) 2008 Everton da Silva Marques
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
20 $QuaggaId: $Format:%an, %ai, %h$ $
32 #include "pim_iface.h"
34 void pim_channel_oil_free(struct channel_oil *c_oil)
36 XFREE(MTYPE_PIM_CHANNEL_OIL, c_oil);
39 static void pim_channel_oil_delete(struct channel_oil *c_oil)
42 notice that listnode_delete() can't be moved
43 into pim_channel_oil_free() because the later is
44 called by list_delete_all_node()
46 listnode_delete(qpim_channel_oil_list, c_oil);
48 pim_channel_oil_free(c_oil);
51 static struct channel_oil *channel_oil_new(struct in_addr group_addr,
52 struct in_addr source_addr,
55 struct channel_oil *c_oil;
56 struct interface *ifp_in;
58 ifp_in = pim_if_find_by_vif_index(input_vif_index);
63 pim_inet4_dump("<group?>", group_addr, group_str, sizeof(group_str));
64 pim_inet4_dump("<source?>", source_addr, source_str, sizeof(source_str));
65 zlog_warn("%s: (S,G)=(%s,%s) could not find input interface for input_vif_index=%d",
67 source_str, group_str, input_vif_index);
70 c_oil = XCALLOC(MTYPE_PIM_CHANNEL_OIL, sizeof(*c_oil));
72 zlog_err("PIM XCALLOC(%zu) failure", sizeof(*c_oil));
76 c_oil->oil.mfcc_mcastgrp = group_addr;
77 c_oil->oil.mfcc_origin = source_addr;
78 c_oil->oil.mfcc_parent = input_vif_index;
79 c_oil->oil_ref_count = 1;
81 zassert(c_oil->oil_size == 0);
86 static struct channel_oil *pim_add_channel_oil(struct in_addr group_addr,
87 struct in_addr source_addr,
90 struct channel_oil *c_oil;
92 c_oil = channel_oil_new(group_addr, source_addr, input_vif_index);
94 zlog_warn("PIM XCALLOC(%zu) failure", sizeof(*c_oil));
98 listnode_add(qpim_channel_oil_list, c_oil);
103 static struct channel_oil *pim_find_channel_oil(struct in_addr group_addr,
104 struct in_addr source_addr)
106 struct listnode *node;
107 struct channel_oil *c_oil;
109 for (ALL_LIST_ELEMENTS_RO(qpim_channel_oil_list, node, c_oil)) {
110 if ((group_addr.s_addr == c_oil->oil.mfcc_mcastgrp.s_addr) &&
111 (source_addr.s_addr == c_oil->oil.mfcc_origin.s_addr))
118 struct channel_oil *pim_channel_oil_add(struct in_addr group_addr,
119 struct in_addr source_addr,
122 struct channel_oil *c_oil;
124 c_oil = pim_find_channel_oil(group_addr, source_addr);
126 ++c_oil->oil_ref_count;
130 return pim_add_channel_oil(group_addr, source_addr, input_vif_index);
133 void pim_channel_oil_del(struct channel_oil *c_oil)
135 --c_oil->oil_ref_count;
137 if (c_oil->oil_ref_count < 1) {
138 pim_channel_oil_delete(c_oil);