Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config MACsec CLI #1895

Closed
wants to merge 8 commits into from
Closed

config MACsec CLI #1895

wants to merge 8 commits into from

Conversation

Pterosaur
Copy link
Contributor

@Pterosaur Pterosaur commented Oct 25, 2021

What I did

Added support for MACsec config

How I did it

Add macsec.py and register macsec command in config/main.py

How to verify it

  1. Add MACsec profile
config macsec profile add [OPTIONS] <profile_name>
  1. Delete MACsec profile
config macsec profile del [OPTIONS] <profile_name>
  1. Add MACsec port
 config macsec port add [OPTIONS] <port_name> <profile_name>
  1. Delete MACsec port
 config macsec port del [OPTIONS] <port_name>

Previous command output (if the output of a command-line utility has changed)

New command output (if the output of a command-line utility has changed)

admin@sonic:$ sudo config macsec profile add -h
Usage: config macsec profile add [OPTIONS] <profile_name>

  Add MACsec profile

Options:
  --priority <priority>           For Key server election. In 0-255 range with
                                  0 being the highest priority.  [default:
                                  255]
  --cipher_suite <cipher_suite>   The cipher suite for MACsec.  [default: GCM-
                                  AES-128]
  --primary_cak <primary_cak>     Primary Connectivity Association Key.
                                  [required]
  --primary_ckn <primary_cak>     Primary CAK Name.  [required]
  --policy <policy>               MACsec policy. INTEGRITY_ONLY: All traffics,
                                  except EAPOL, will be converted to MACsec
                                  packets without encryption.SECURITY: All
                                  traffics, except EAPOL, will be encrypted by
                                  SecY.  [default: security]
  --enable_replay_protect / --disable_replay_protect
                                  Whether enable replay protect.  [default:
                                  False]
  --replay_window <enable_replay_protect>
                                  Replay window size that is the number of
                                  packets that could be out of order. This
                                  filed works only if ENABLE_REPLAY_PROTECT is
                                  true.  [default: 0]
  --send_sci / --no_send_sci      Whether send SCI.  [default: True]
  --rekey_period <rekey_period>   The period of proactively refresh (Unit
                                  second).  [default: 0]
  -?, -h, --help                  Show this message and exit.

admin@sonic:$ sudo config macsec profile del -h

Usage: config macsec profile del [OPTIONS] <profile_name>

  Delete MACsec profile

Options:
  -h, -?, --help  Show this message and exit.

admin@sonic$ sudo config macsec port add -h
Usage: config macsec port add [OPTIONS] <port_name> <profile_name>

  Add MACsec port

Options:
  -h, -?, --help  Show this message and exit.

admin@sonic$ sudo config macsec port del -h
Usage: config macsec port del [OPTIONS] <port_name>

  Delete MACsec port

Options:
  -h, -?, --help  Show this message and exit.

@lgtm-com
Copy link

lgtm-com bot commented Oct 25, 2021

This pull request introduces 1 alert when merging 5eda315 into 8ea834b - view on LGTM.com

new alerts:

  • 1 for Unused import

Signed-off-by: Ze Gan <ganze718@gmail.com>
Signed-off-by: Ze Gan <ganze718@gmail.com>
@Pterosaur Pterosaur marked this pull request as ready for review October 25, 2021 17:59
@Pterosaur
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Pterosaur
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

config/macsec.py Outdated
@click.option('--cipher_suite', metavar='<cipher_suite>', required=False, default="GCM-AES-128", show_default=True, type=click.Choice(["GCM-AES-128", "GCM-AES-256", "GCM-AES-XPN-128", "GCM-AES-XPN-256"]), help="The cipher suite for MACsec.")
@click.option('--primary_cak', metavar='<primary_cak>', required=True, type=str, help="Primary Connectivity Association Key.")
@click.option('--primary_ckn', metavar='<primary_cak>', required=True, type=str, help="Primary CAK Name.")
@click.option('--policy', metavar='<policy>', required=False, default="security", show_default=True, type=click.Choice(["integrity_only", "security"]), help="MACsec policy. INTEGRITY_ONLY: All traffics, except EAPOL, will be converted to MACsec packets without encryption.SECURITY: All traffics, except EAPOL, will be encrypted by SecY.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor typos: change traffics to traffic and add space between period and SECURITY.

config/macsec.py Outdated
@click.option('--primary_ckn', metavar='<primary_cak>', required=True, type=str, help="Primary CAK Name.")
@click.option('--policy', metavar='<policy>', required=False, default="security", show_default=True, type=click.Choice(["integrity_only", "security"]), help="MACsec policy. INTEGRITY_ONLY: All traffics, except EAPOL, will be converted to MACsec packets without encryption.SECURITY: All traffics, except EAPOL, will be encrypted by SecY.")
@click.option('--enable_replay_protect/--disable_replay_protect', metavar='<replay_protect>', required=False, default=False, show_default=True, is_flag=True, help="Whether enable replay protect.")
@click.option('--replay_window', metavar='<enable_replay_protect>', required=False, default=0, show_default=True, type=click.IntRange(0, 2**32), help="Replay window size that is the number of packets that could be out of order. This filed works only if ENABLE_REPLAY_PROTECT is true.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor typo: change filed to field.

config/macsec.py Outdated
profile_table["send_sci"] = send_sci

if rekey_period > 0:
profile_table["replay_period"] = rekey_period
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replay_period should be rekey_period

assert "enable_replay_protect" not in profile_table
assert "replay_window" not in profile_table
assert profile_table["send_sci"] == "1"
assert "replay_period" not in profile_table
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is any field called replay_period? There is only replay_window and rekey_period AFAIK?

assert profile_table["send_sci"] == "1"
if "no_send_sci" in profile_map:
assert profile_table["send_sci"] == "0"
if "replay_period" in profile_map:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, replay_period should be rekey_period?

@qbdwlr
Copy link
Contributor

qbdwlr commented Nov 6, 2021

I have implemented and tested the changes I suggested above... You can find the updated files if you want to copy the changes in #1727

@Pterosaur Pterosaur marked this pull request as draft November 7, 2021 15:40
@qbdwlr qbdwlr mentioned this pull request Nov 9, 2021
@Pterosaur
Copy link
Contributor Author

MACsec CLI implemented by PR: sonic-net/sonic-buildimage#9390

@Pterosaur Pterosaur closed this May 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants