mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-07-17 15:46:26 +00:00
bgpd: Update routemap example with new script call
Signed-off-by: Donald Lee <dlqs@gmx.com>
This commit is contained in:
parent
81fde499e5
commit
fa2bb2e8d3
@ -29,6 +29,7 @@
|
|||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "frrlua.h"
|
#include "frrlua.h"
|
||||||
|
#include "frrscript.h"
|
||||||
#ifdef HAVE_LIBPCREPOSIX
|
#ifdef HAVE_LIBPCREPOSIX
|
||||||
#include <pcreposix.h>
|
#include <pcreposix.h>
|
||||||
#else
|
#else
|
||||||
@ -373,42 +374,27 @@ route_match_script(void *rule, const struct prefix *prefix, void *object)
|
|||||||
return RMAP_NOMATCH;
|
return RMAP_NOMATCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum frrlua_rm_status status_failure = LUA_RM_FAILURE,
|
enum frrlua_rm_status lrm_status = LUA_RM_FAILURE,
|
||||||
status_nomatch = LUA_RM_NOMATCH,
|
status_nomatch = LUA_RM_NOMATCH,
|
||||||
status_match = LUA_RM_MATCH,
|
status_match = LUA_RM_MATCH,
|
||||||
status_match_and_change = LUA_RM_MATCH_AND_CHANGE;
|
status_match_and_change = LUA_RM_MATCH_AND_CHANGE;
|
||||||
|
|
||||||
/* Make result values available */
|
int result = frrscript_call(
|
||||||
struct frrscript_env env[] = {
|
fs, ("RM_FAILURE", (long long *)&lrm_status),
|
||||||
{"integer", "RM_FAILURE", &status_failure},
|
("RM_NOMATCH", (long long *)&status_nomatch),
|
||||||
{"integer", "RM_NOMATCH", &status_nomatch},
|
("RM_MATCH", (long long *)&status_match),
|
||||||
{"integer", "RM_MATCH", &status_match},
|
("RM_MATCH_AND_CHANGE", (long long *)&status_match_and_change),
|
||||||
{"integer", "RM_MATCH_AND_CHANGE", &status_match_and_change},
|
("action", (long long *)&lrm_status), ("prefix", prefix),
|
||||||
{"integer", "action", &status_failure},
|
("attributes", path->attr), ("peer", path->peer));
|
||||||
{"prefix", "prefix", prefix},
|
|
||||||
{"attr", "attributes", path->attr},
|
|
||||||
{"peer", "peer", path->peer},
|
|
||||||
{}};
|
|
||||||
|
|
||||||
struct frrscript_env results[] = {
|
|
||||||
{"integer", "action"},
|
|
||||||
{"attr", "attributes"},
|
|
||||||
{},
|
|
||||||
};
|
|
||||||
|
|
||||||
int result = frrscript_call(fs, env);
|
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
zlog_err("Issue running script rule; defaulting to no match");
|
zlog_err("Issue running script rule; defaulting to no match");
|
||||||
return RMAP_NOMATCH;
|
return RMAP_NOMATCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum frrlua_rm_status *lrm_status =
|
|
||||||
frrscript_get_result(fs, &results[0]);
|
|
||||||
|
|
||||||
int status = RMAP_NOMATCH;
|
int status = RMAP_NOMATCH;
|
||||||
|
|
||||||
switch (*lrm_status) {
|
switch (lrm_status) {
|
||||||
case LUA_RM_FAILURE:
|
case LUA_RM_FAILURE:
|
||||||
zlog_err(
|
zlog_err(
|
||||||
"Executing route-map match script '%s' failed; defaulting to no match",
|
"Executing route-map match script '%s' failed; defaulting to no match",
|
||||||
@ -421,29 +407,12 @@ route_match_script(void *rule, const struct prefix *prefix, void *object)
|
|||||||
case LUA_RM_MATCH_AND_CHANGE:
|
case LUA_RM_MATCH_AND_CHANGE:
|
||||||
status = RMAP_MATCH;
|
status = RMAP_MATCH;
|
||||||
zlog_debug("Updating attribute based on script's values");
|
zlog_debug("Updating attribute based on script's values");
|
||||||
|
|
||||||
uint32_t locpref = 0;
|
|
||||||
struct attr *newattr = frrscript_get_result(fs, &results[1]);
|
|
||||||
|
|
||||||
path->attr->med = newattr->med;
|
|
||||||
|
|
||||||
if (path->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
|
|
||||||
locpref = path->attr->local_pref;
|
|
||||||
if (locpref != newattr->local_pref) {
|
|
||||||
SET_FLAG(path->attr->flag,
|
|
||||||
ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF));
|
|
||||||
path->attr->local_pref = newattr->local_pref;
|
|
||||||
}
|
|
||||||
|
|
||||||
aspath_free(newattr->aspath);
|
|
||||||
XFREE(MTYPE_TMP, newattr);
|
|
||||||
break;
|
break;
|
||||||
case LUA_RM_MATCH:
|
case LUA_RM_MATCH:
|
||||||
status = RMAP_MATCH;
|
status = RMAP_MATCH;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
XFREE(MTYPE_TMP, lrm_status);
|
|
||||||
frrscript_unload(fs);
|
frrscript_unload(fs);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
|
Loading…
Reference in New Issue
Block a user