vrf_id == VRF_DEFAULT
? BGP_INSTANCE_TYPE_DEFAULT
: BGP_INSTANCE_TYPE_VRF,
- NULL);
+ NULL, ASNOTATION_UNDEFINED);
switch (ret) {
case BGP_ERR_AS_MISMATCH:
flog_err(EC_BGP_EVPN_AS_MISMATCH,
}
int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
- enum bgp_instance_type inst_type, const char *as_pretty)
+ enum bgp_instance_type inst_type, const char *as_pretty,
+ enum asnotation_mode asnotation)
{
- int ret = bgp_get(bgp, as, name, inst_type, as_pretty);
+ int ret = bgp_get(bgp, as, name, inst_type, as_pretty, asnotation);
if (ret == BGP_CREATED) {
bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
/* "router bgp" commands. */
DEFUN_NOSH (router_bgp,
router_bgp_cmd,
- "router bgp [ASNUM$instasn [<view|vrf> VIEWVRFNAME]]",
+ "router bgp [ASNUM$instasn [<view|vrf> VIEWVRFNAME] [as-notation <dot|dot+|plain>]]",
ROUTER_STR
BGP_STR
AS_STR
- BGP_INSTANCE_HELP_STR)
+ BGP_INSTANCE_HELP_STR
+ "Force the AS notation output\n"
+ "use 'AA.BB' format for AS 4 byte values\n"
+ "use 'AA.BB' format for all AS values\n"
+ "use plain format for all AS values\n")
{
int idx_asn = 2;
int idx_view_vrf = 3;
int idx_vrf = 4;
int is_new_bgp = 0;
+ int idx_asnotation = 3;
+ int idx_asnotation_kind = 4;
+ enum asnotation_mode asnotation = ASNOTATION_UNDEFINED;
int ret;
as_t as;
struct bgp *bgp;
BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
inst_type = BGP_INSTANCE_TYPE_DEFAULT;
- if (argc > 3) {
- name = argv[idx_vrf]->arg;
- if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
- if (strmatch(name, VRF_DEFAULT_NAME))
- name = NULL;
- else
- inst_type = BGP_INSTANCE_TYPE_VRF;
- } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
- inst_type = BGP_INSTANCE_TYPE_VIEW;
+ if (argv_find(argv, argc, "VIEWVRFNAME", &idx_vrf)) {
+ idx_view_vrf = idx_vrf - 1;
+ if (argv[idx_view_vrf]->text) {
+ name = argv[idx_vrf]->arg;
+
+ if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
+ if (strmatch(name, VRF_DEFAULT_NAME))
+ name = NULL;
+ else
+ inst_type =
+ BGP_INSTANCE_TYPE_VRF;
+ } else if (!strcmp(argv[idx_view_vrf]->text,
+ "view"))
+ inst_type = BGP_INSTANCE_TYPE_VIEW;
+ }
+ }
+ if (argv_find(argv, argc, "as-notation", &idx_asnotation)) {
+ idx_asnotation_kind = idx_asnotation + 1;
+ if (strmatch(argv[idx_asnotation_kind]->text, "dot+"))
+ asnotation = ASNOTATION_DOTPLUS;
+ else if (strmatch(argv[idx_asnotation_kind]->text,
+ "dot"))
+ asnotation = ASNOTATION_DOT;
+ else if (strmatch(argv[idx_asnotation_kind]->text,
+ "plain"))
+ asnotation = ASNOTATION_PLAIN;
}
if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
is_new_bgp = (bgp_lookup(as, name) == NULL);
ret = bgp_get_vty(&bgp, &as, name, inst_type,
- argv[idx_asn]->arg);
+ argv[idx_asn]->arg, asnotation);
switch (ret) {
case BGP_ERR_AS_MISMATCH:
vty_out(vty, "BGP is already running; AS is %s\n",
bgp_vpn_leak_export(bgp);
/* Pending: handle when user tries to change a view to vrf n vv.
*/
+ /* for pre-existing bgp instance,
+ * - update as_pretty
+ * - update asnotation if explicitly mentioned
+ */
+ if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO)) {
+ XFREE(MTYPE_BGP, bgp->as_pretty);
+ bgp->as_pretty = XSTRDUP(MTYPE_BGP, argv[idx_asn]->arg);
+ if (!CHECK_FLAG(bgp->config, BGP_CONFIG_ASNOTATION) &&
+ asnotation != ASNOTATION_UNDEFINED) {
+ SET_FLAG(bgp->config, BGP_CONFIG_ASNOTATION);
+ bgp->asnotation = asnotation;
+ }
+ }
}
/* unset the auto created flag as the user config is now present */
/* "no router bgp" commands. */
DEFUN (no_router_bgp,
no_router_bgp_cmd,
- "no router bgp [ASNUM$instasn [<view|vrf> VIEWVRFNAME]]",
+ "no router bgp [ASNUM$instasn [<view|vrf> VIEWVRFNAME] [as-notation <dot|dot+|plain>]]",
NO_STR
ROUTER_STR
BGP_STR
AS_STR
- BGP_INSTANCE_HELP_STR)
+ BGP_INSTANCE_HELP_STR
+ "Force the AS notation output\n"
+ "use 'AA.BB' format for AS 4 byte values\n"
+ "use 'AA.BB' format for all AS values\n"
+ "use plain format for all AS values\n")
{
int idx_asn = 3;
int idx_vrf = 5;
return CMD_SUCCESS;
}
-
/* BGP Cluster ID. */
DEFUN (bgp_cluster_id,
bgp_cluster_id_cmd,
/* Auto-create assuming the same AS */
ret = bgp_get_vty(&bgp_default, &as, NULL,
- BGP_INSTANCE_TYPE_DEFAULT, NULL);
+ BGP_INSTANCE_TYPE_DEFAULT, NULL,
+ ASNOTATION_UNDEFINED);
if (ret) {
vty_out(vty,
if (!bgp_default) {
/* Auto-create assuming the same AS */
ret = bgp_get_vty(&bgp_default, &as, NULL,
- BGP_INSTANCE_TYPE_DEFAULT, NULL);
+ BGP_INSTANCE_TYPE_DEFAULT, NULL,
+ ASNOTATION_UNDEFINED);
if (ret) {
vty_out(vty,
vrf_bgp = bgp_default;
else
/* Auto-create assuming the same AS */
- ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type, NULL);
-
+ ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type,
+ NULL, ASNOTATION_UNDEFINED);
if (ret) {
vty_out(vty,
"VRF %s is not configured as a bgp instance\n",
vty_out(vty, " %s %s",
(bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
? "view" : "vrf", bgp->name);
+ if (CHECK_FLAG(bgp->config, BGP_CONFIG_ASNOTATION))
+ vty_out(vty, " as-notation %s",
+ asn_mode2str(bgp->asnotation));
+
vty_out(vty, "\n");
/* BGP fast-external-failover. */
extern void community_alias_vty(void);
extern const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json);
extern int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
- enum bgp_instance_type inst_type, const char *as_pretty);
+ enum bgp_instance_type inst_type, const char *as_pretty,
+ enum asnotation_mode asnotation);
extern void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp);
extern void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp);
extern void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp);
/* BGP instance creation by `router bgp' commands. */
static struct bgp *bgp_create(as_t *as, const char *name,
enum bgp_instance_type inst_type,
- const char *as_pretty)
+ const char *as_pretty,
+ enum asnotation_mode asnotation)
{
struct bgp *bgp;
afi_t afi;
else
bgp->as_pretty = XSTRDUP(MTYPE_BGP, asn_asn2asplain(*as));
+ if (asnotation != ASNOTATION_UNDEFINED) {
+ bgp->asnotation = asnotation;
+ SET_FLAG(bgp->config, BGP_CONFIG_ASNOTATION);
+ } else
+ asn_str2asn_notation(bgp->as_pretty, NULL, &bgp->asnotation);
+
if (BGP_DEBUG(zebra, ZEBRA)) {
if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
zlog_debug("Creating Default VRF, AS %s",
/* Called from VTY commands. */
int bgp_get(struct bgp **bgp_val, as_t *as, const char *name,
- enum bgp_instance_type inst_type, const char *as_pretty)
+ enum bgp_instance_type inst_type, const char *as_pretty,
+ enum asnotation_mode asnotation)
{
struct bgp *bgp;
struct vrf *vrf = NULL;
if (ret || *bgp_val)
return ret;
- bgp = bgp_create(as, name, inst_type, as_pretty);
+ bgp = bgp_create(as, name, inst_type, as_pretty, asnotation);
/*
* view instances will never work inside of a vrf
uint16_t config;
#define BGP_CONFIG_CLUSTER_ID (1 << 0)
#define BGP_CONFIG_CONFEDERATION (1 << 1)
+#define BGP_CONFIG_ASNOTATION (1 << 2)
/* BGP router identifier. */
struct in_addr router_id;
bool allow_martian;
+ enum asnotation_mode asnotation;
+
QOBJ_FIELDS;
};
DECLARE_QOBJ_TYPE(bgp);
extern void bgp_option_norib_unset_runtime(void);
extern int bgp_get(struct bgp **bgp, as_t *as, const char *name,
- enum bgp_instance_type kind, const char *as_pretty);
+ enum bgp_instance_type kind, const char *as_pretty,
+ enum asnotation_mode asnotation);
extern void bgp_instance_up(struct bgp *);
extern void bgp_instance_down(struct bgp *);
extern int bgp_delete(struct bgp *);
-----------------
First of all you must configure BGP router with the :clicmd:`router bgp ASN`
-command. The AS number is an identifier for the autonomous system. The BGP
-protocol uses the AS number for detecting whether the BGP connection is
+command. The AS number is an identifier for the autonomous system. The AS
+identifier can either be a number or two numbers separated by a period. The
+BGP protocol uses the AS identifier for detecting whether the BGP connection is
internal or external.
.. clicmd:: router bgp ASN
vpn_policy[AFI_IP].tovpn_sid: none
vpn_policy[AFI_IP6].tovpn_sid: 2001:db8:1:1::200
+AS-notation support
+-------------------
+
+By default, the ASN value output follows how the BGP ASN instance is
+expressed in the configuration. Three as-notation outputs are available:
+
+- plain output: both AS4B and AS2B use a single number.
+ ` router bgp 65536`.
+
+- dot output: AS4B values are using two numbers separated by a period.
+ `router bgp 1.1` means that the AS number is 65536.
+
+- dot+ output: AS2B and AS4B values are using two numbers separated by a
+ period. `router bgp 0.5` means that the AS number is 5.
+
+The below option permits forcing the as-notation output:
+
+.. clicmd:: router bgp ASN as-notation dot|dot+|plain
+
+ The chosen as-notation format will override the BGP ASN output.
.. _bgp-route-reflector:
static bool relax_as_zero;
+static const struct message asnotation_mode_msg[] = {
+ {ASNOTATION_PLAIN, "plain"},
+ {ASNOTATION_DOT, "dot"},
+ {ASNOTATION_DOTPLUS, "dot+"},
+ {ASNOTATION_UNDEFINED, "undefined"},
+ {0}
+};
+
/* converts a string into an Autonomous system number
* "1.1" => 65536
* "65500" => 65500
*/
static bool asn_str2asn_internal(const char *asstring, as_t *asn,
- const char **next, bool *partial)
+ const char **next, bool *partial,
+ enum asnotation_mode *mode)
{
uint32_t high = 0, low = 0;
uint64_t temp_val;
const char *p = asstring;
bool ret = false;
uint32_t digit;
+ enum asnotation_mode val = ASNOTATION_PLAIN;
if (!asstring)
goto end;
*partial = true;
goto end;
}
- if (!asn) {
- ret = true;
- goto end;
- }
- *asn = (high << 16) + low;
+ if (asn)
+ *asn = (high << 16) + low;
ret = true;
+ if (high == 0)
+ val = ASNOTATION_DOTPLUS;
+ else
+ val = ASNOTATION_DOT;
goto end;
}
/* AS 0 is forbidden */
end:
if (next)
*next = p;
+ if (mode)
+ *mode = val;
return ret;
}
bool asn_str2asn(const char *asstring, as_t *asn)
{
- return asn_str2asn_internal(asstring, asn, NULL, NULL);
+ return asn_str2asn_internal(asstring, asn, NULL, NULL, NULL);
}
const char *asn_asn2asplain(as_t asn)
const char **next = &p;
bool found;
- found = asn_str2asn_internal(asstring, asn, next, NULL);
+ found = asn_str2asn_internal(asstring, asn, next, NULL, NULL);
if (found_ptr)
*found_ptr = found;
return *next;
{
bool found, partial = false;
- found = asn_str2asn_internal(str, NULL, NULL, &partial);
+ found = asn_str2asn_internal(str, NULL, NULL, &partial, NULL);
if (found && !partial)
return exact_match;
return no_match;
}
+
+bool asn_str2asn_notation(const char *asstring, as_t *asn,
+ enum asnotation_mode *asnotation)
+{
+ return asn_str2asn_internal(asstring, asn, NULL, NULL, asnotation);
+}
+
+const char *asn_mode2str(enum asnotation_mode asnotation)
+{
+ return lookup_msg(asnotation_mode_msg, asnotation,
+ "Unrecognized AS notation mode");
+}
#define ASN_STRING_MAX_SIZE 12
+enum asnotation_mode {
+ ASNOTATION_PLAIN = 0,
+ ASNOTATION_DOT,
+ ASNOTATION_DOTPLUS,
+ ASNOTATION_UNDEFINED,
+};
+
typedef uint32_t as_t;
extern bool asn_str2asn(const char *asstring, as_t *asn);
extern const char *asn_str2asn_parse(const char *asstring, as_t *asn,
bool *found_ptr);
extern enum match_type asn_str2asn_match(const char *str);
+extern bool asn_str2asn_notation(const char *asstring, as_t *asn,
+ enum asnotation_mode *asnotation);
+extern const char *asn_mode2str(enum asnotation_mode asnotation);
/* for test */
extern void asn_relax_as_zero(bool relax);
if (fileno(stdout) >= 0)
tty = isatty(fileno(stdout));
- if (bgp_get(&bgp, &asn, NULL, BGP_INSTANCE_TYPE_DEFAULT,
- NULL) < 0)
+ if (bgp_get(&bgp, &asn, NULL, BGP_INSTANCE_TYPE_DEFAULT, NULL,
+ ASNOTATION_PLAIN) < 0)
return -1;
peer = peer_create_accept(bgp);
if (fileno(stdout) >= 0)
tty = isatty(fileno(stdout));
- if (bgp_get(&bgp, &asn, NULL, BGP_INSTANCE_TYPE_DEFAULT,
- NULL) < 0)
+ if (bgp_get(&bgp, &asn, NULL, BGP_INSTANCE_TYPE_DEFAULT, NULL,
+ ASNOTATION_PLAIN) < 0)
return -1;
peer = peer_create_accept(bgp);
vrf_init(NULL, NULL, NULL, NULL);
bgp_option_set(BGP_OPT_NO_LISTEN);
- if (bgp_get(&bgp, &asn, NULL, BGP_INSTANCE_TYPE_DEFAULT,
- NULL) < 0)
+ if (bgp_get(&bgp, &asn, NULL, BGP_INSTANCE_TYPE_DEFAULT, NULL,
+ ASNOTATION_PLAIN) < 0)
return -1;
peer = peer_create_accept(bgp);
#ifdef HAVE_BGPD
DEFUNSH(VTYSH_BGPD, router_bgp, router_bgp_cmd,
- "router bgp [ASNUM [<view|vrf> VIEWVRFNAME]]",
+ "router bgp [ASNUM [<view|vrf> VIEWVRFNAME] [as-notation <dot|dot+|plain>]]",
ROUTER_STR BGP_STR AS_STR
"BGP view\nBGP VRF\n"
- "View/VRF name\n")
+ "View/VRF name\n"
+ "Force the AS notation output\n"
+ "use 'AA.BB' format for AS 4 byte values\n"
+ "use 'AA.BB' format for all AS values\n"
+ "use plain format for all AS values\n")
{
vty->node = BGP_NODE;
return CMD_SUCCESS;