aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/mfib/mfib_entry_src_rr.c
blob: a6a1e0d8aa513de9b84e3ce37639e81fa96dd779 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * Copyright (c) 2018 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


#include <vnet/mfib/mfib_entry_src.h>
#include <vnet/mfib/mfib_entry_cover.h>
#include <vnet/mfib/mfib_table.h>
#include <vnet/fib/fib_path_list.h>

static void
mfib_entry_src_rr_deactiviate (mfib_entry_t *mfib_entry,
                               mfib_entry_src_t *msrc)
{
    mfib_entry_t *cover;

    /*
     * remove the depednecy on the covering entry
     */
    if (FIB_NODE_INDEX_INVALID != msrc->mfes_cover)
    {
	cover = mfib_entry_get(msrc->mfes_cover);
	mfib_entry_cover_untrack(cover, msrc->mfes_sibling);
	msrc->mfes_cover = FIB_NODE_INDEX_INVALID;
    }

    fib_path_list_unlock(msrc->mfes_pl);
    msrc->mfes_pl = FIB_NODE_INDEX_INVALID;
    msrc->mfes_itfs = NULL;
    msrc->mfes_exts = NULL;
}

static void
mfib_entry_src_rr_activiate (mfib_entry_t *mfib_entry,
                             mfib_entry_src_t *msrc)
{
    mfib_entry_src_t *csrc;
    mfib_entry_t *cover;

    msrc->mfes_cover = mfib_table_get_less_specific(mfib_entry->mfe_fib_index,
                                                    &mfib_entry->mfe_prefix);

    ASSERT(FIB_NODE_INDEX_INVALID != msrc->mfes_cover);

    cover = mfib_entry_get(msrc->mfes_cover);

    msrc->mfes_sibling =
	mfib_entry_cover_track(cover, mfib_entry_get_index(mfib_entry));

    csrc = mfib_entry_get_best_src(cover);

    msrc->mfes_pl = csrc->mfes_pl;
    fib_path_list_lock(msrc->mfes_pl);
    msrc->mfes_route_flags = csrc->mfes_route_flags;
    msrc->mfes_itfs = csrc->mfes_itfs;
    msrc->mfes_exts = csrc->mfes_exts;
    msrc->mfes_rpf_id = csrc->mfes_rpf_id;
}

static mfib_src_res_t
mfib_entry_src_rr_cover_change (mfib_entry_t *mfib_entry,
                                mfib_entry_src_t *msrc)
{
    mfib_entry_src_rr_deactiviate(mfib_entry, msrc);
    mfib_entry_src_rr_activiate(mfib_entry, msrc);

    return (MFIB_SRC_REEVALUATE);
}

static mfib_src_res_t
mfib_entry_src_rr_cover_update (mfib_entry_t *mfib_entry,
                                mfib_entry_src_t *msrc)
{
    /*
     * path lists are updated (i.e. not shared) in the mfib world,
     * so there's no need to check for a new one. but we do need to
     * copy down any new flags and input interfaces
     */
    mfib_entry_t *cover;

    cover = mfib_entry_get(msrc->mfes_cover);

    msrc->mfes_route_flags = cover->mfe_flags;
    msrc->mfes_itfs = cover->mfe_itfs;
    msrc->mfes_rpf_id = cover->mfe_rpf_id;

    return (MFIB_SRC_REEVALUATE);
}

void
mfib_entry_src_rr_module_init (void)
{
    mfib_entry_src_vft mvft = {
        .mev_activate = mfib_entry_src_rr_activiate,
        .mev_deactivate = mfib_entry_src_rr_deactiviate,
        .mev_cover_change = mfib_entry_src_rr_cover_change,
        .mev_cover_update = mfib_entry_src_rr_cover_update,
    };

    mfib_entry_src_register(MFIB_SOURCE_RR, &mvft);
}