]>
git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_pbr.c
1 /* Zebra Policy Based Routing (PBR) main handling.
2 * Copyright (C) 2018 Cumulus Networks, Inc.
4 * This file is part of FRR.
6 * FRR is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * FRR is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with FRR; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 #include "zebra/zebra_pbr.h"
32 /* static function declarations */
34 /* Private functions */
36 /* Public functions */
37 void zebra_pbr_rules_free(void *arg
)
39 struct zebra_pbr_rule
*rule
;
41 rule
= (struct zebra_pbr_rule
*)arg
;
43 kernel_del_pbr_rule(rule
);
44 XFREE(MTYPE_TMP
, rule
);
47 uint32_t zebra_pbr_rules_hash_key(void *arg
)
49 struct zebra_pbr_rule
*rule
;
52 rule
= (struct zebra_pbr_rule
*)arg
;
53 key
= jhash_3words(rule
->seq
, rule
->priority
, rule
->action
.table
,
54 prefix_hash_key(&rule
->filter
.src_ip
));
56 key
= jhash_1word(rule
->ifp
->ifindex
, key
);
58 key
= jhash_1word(0, key
);
60 return jhash_3words(rule
->filter
.src_port
, rule
->filter
.dst_port
,
61 prefix_hash_key(&rule
->filter
.dst_ip
), key
);
64 int zebra_pbr_rules_hash_equal(const void *arg1
, const void *arg2
)
66 const struct zebra_pbr_rule
*r1
, *r2
;
68 r1
= (const struct zebra_pbr_rule
*)arg1
;
69 r2
= (const struct zebra_pbr_rule
*)arg2
;
71 if (r1
->seq
!= r2
->seq
)
74 if (r1
->priority
!= r2
->priority
)
77 if (r1
->action
.table
!= r2
->action
.table
)
80 if (r1
->filter
.src_port
!= r2
->filter
.src_port
)
83 if (r1
->filter
.dst_port
!= r2
->filter
.dst_port
)
86 if (!prefix_same(&r1
->filter
.src_ip
, &r2
->filter
.src_ip
))
89 if (!prefix_same(&r1
->filter
.dst_ip
, &r2
->filter
.dst_ip
))
92 if (r1
->ifp
!= r2
->ifp
)
98 static void *pbr_rule_alloc_intern(void *arg
)
100 struct zebra_pbr_rule
*zpr
;
101 struct zebra_pbr_rule
*new;
103 zpr
= (struct zebra_pbr_rule
*)arg
;
105 new = XCALLOC(MTYPE_TMP
, sizeof(*new));
107 memcpy(new, zpr
, sizeof(*zpr
));
112 void zebra_pbr_add_rule(struct zebra_ns
*zns
, struct zebra_pbr_rule
*rule
)
114 (void)hash_get(zns
->rules_hash
, rule
, pbr_rule_alloc_intern
);
115 kernel_add_pbr_rule(rule
);
118 void zebra_pbr_del_rule(struct zebra_ns
*zns
, struct zebra_pbr_rule
*rule
)
120 struct zebra_pbr_rule
*lookup
;
122 lookup
= hash_lookup(zns
->rules_hash
, rule
);
123 kernel_del_pbr_rule(rule
);
126 XFREE(MTYPE_TMP
, lookup
);
128 zlog_warn("%s: Rule being deleted we know nothing about",
129 __PRETTY_FUNCTION__
);
133 * Handle success or failure of rule (un)install in the kernel.
135 void kernel_pbr_rule_add_del_status(struct zebra_pbr_rule
*rule
,
136 enum southbound_results res
)
141 * Handle rule delete notification from kernel.
143 int kernel_pbr_rule_del(struct zebra_pbr_rule
*rule
)