diff options
| author | Jafar Al-Gharaibeh <jafar@atcorp.com> | 2022-10-29 16:57:34 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-29 16:57:34 -0500 |
| commit | 109fe83ac07dbb72de340f7edfbcecfc4f0e4f06 (patch) | |
| tree | a91cf19db1526a9afb5ccdf7fa2db3ecfe0dc89e /ospfclient/ospfclient.py | |
| parent | 99267afe94eb286cf3f55db4244982022058096a (diff) | |
| parent | d9374552cb2584cb4fdc2da407ba44e141b8436c (diff) | |
Merge pull request #12223 from FRRouting/mergify/bp/dev/8.4/pr-12172
OSPF opaques LSA API - fix bug with LL API delete, add option for zero data length withdrawals (backport #12172)
Diffstat (limited to 'ospfclient/ospfclient.py')
| -rwxr-xr-x | ospfclient/ospfclient.py | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/ospfclient/ospfclient.py b/ospfclient/ospfclient.py index 19561145a0..8e3c68445f 100755 --- a/ospfclient/ospfclient.py +++ b/ospfclient/ospfclient.py @@ -62,13 +62,16 @@ smsg_info = { MSG_REGISTER_EVENT: ("REGISTER_EVENT", FMT_LSA_FILTER), MSG_SYNC_LSDB: ("SYNC_LSDB", FMT_LSA_FILTER), MSG_ORIGINATE_REQUEST: ("ORIGINATE_REQUEST", ">II" + FMT_LSA_HEADER[1:]), - MSG_DELETE_REQUEST: ("DELETE_REQUEST", ">IBBxxL"), + MSG_DELETE_REQUEST: ("DELETE_REQUEST", ">IBBxBL"), MSG_SYNC_REACHABLE: ("MSG_SYNC_REACHABLE", ""), MSG_SYNC_ISM: ("MSG_SYNC_ISM", ""), MSG_SYNC_NSM: ("MSG_SYNC_NSM", ""), MSG_SYNC_ROUTER_ID: ("MSG_SYNC_ROUTER_ID", ""), } +# OSPF API MSG Delete Flag. +OSPF_API_DEL_ZERO_LEN_LSA = 0x01 # send withdrawal with no LSA data + # -------------------------- # Messages from OSPF daemon. # -------------------------- @@ -842,7 +845,7 @@ class OspfOpaqueClient(OspfApiClient): await self._assure_opaque_ready(lsa_type, otype) await self.msg_send_raises(mt, msg) - async def delete_opaque_data(self, addr, lsa_type, otype, oid): + async def delete_opaque_data(self, addr, lsa_type, otype, oid, flags=0): """Delete an instance of opaque data. Delete an instance of opaque data. This call will register for the given @@ -854,6 +857,7 @@ class OspfOpaqueClient(OspfApiClient): otype: (octet) opaque type. Note: the type will be registered if the user has not explicity done that yet with `register_opaque_data`. oid: (3 octets) ID of this opaque data + flags: (octet) optional flags (e.g., OSPF_API_DEL_ZERO_LEN_LSA, defaults to no flags) Raises: See `msg_send_raises` """ @@ -862,7 +866,7 @@ class OspfOpaqueClient(OspfApiClient): mt = MSG_DELETE_REQUEST await self._assure_opaque_ready(lsa_type, otype) - mp = struct.pack(msg_fmt[mt], int(addr), lsa_type, otype, oid) + mp = struct.pack(msg_fmt[mt], int(addr), lsa_type, otype, flags, oid) await self.msg_send_raises(mt, mp) async def register_opaque_data(self, lsa_type, otype, callback=None): @@ -1115,23 +1119,28 @@ async def async_main(args): except ValueError: addr = ip(aval) oargs = [addr, ltype, int(_s.pop(False)), int(_s.pop(False))] - assert len(_s) <= 1, "Bad format for action argument" - try: - b = bytes.fromhex(_s.pop(False)) - except IndexError: - b = b"" - logging.info("opaque data is %s octets", len(b)) - # Needs to be multiple of 4 in length - mod = len(b) % 4 - if mod: - b += b"\x00" * (4 - mod) - logging.info("opaque padding to %s octets", len(b)) - if what.casefold() == "add": + try: + b = bytes.fromhex(_s.pop(False)) + except IndexError: + b = b"" + logging.info("opaque data is %s octets", len(b)) + # Needs to be multiple of 4 in length + mod = len(b) % 4 + if mod: + b += b"\x00" * (4 - mod) + logging.info("opaque padding to %s octets", len(b)) + await c.add_opaque_data(*oargs, b) else: assert what.casefold().startswith("del") - await c.delete_opaque_data(*oargs) + f = 0 + if len(_s) >= 1: + try: + f = int(_s.pop(False)) + except IndexError: + f = 0 + await c.delete_opaque_data(*oargs, f) if args.exit: return 0 except Exception as error: @@ -1153,7 +1162,9 @@ def main(*args): ap.add_argument("--server", default="localhost", help="OSPF API server") ap.add_argument("-v", "--verbose", action="store_true", help="be verbose") ap.add_argument( - "actions", nargs="*", help="(ADD|DEL),LSATYPE,[ADDR,],OTYPE,OID,[HEXDATA]" + "actions", + nargs="*", + help="(ADD|DEL),LSATYPE,[ADDR,],OTYPE,OID,[HEXDATA|DEL_FLAG]", ) args = ap.parse_args() |
