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

caclmgrd: monitor state_db to update dhcp acl #8222

Merged
5 commits merged into from
Aug 7, 2021
Merged

Conversation

ghost
Copy link

@ghost ghost commented Jul 19, 2021

caclmgrd: monitor mux_cable_table in state_db to update dhcp acl

  • if the state changes to 'standby', add acl to block dhcp packets based on ingress interfaces
  • if the state changes to 'active', delete acl
  • if the state changes to 'unknown', also delete acl to avoid potential disconnect
  • both addition and deletion follow checking the existence of the rules

The change has been verified on a virtual switch based testbed.

@ghost ghost requested a review from lguohan as a code owner July 19, 2021 17:23
@ghost ghost requested review from abdosi, prsunny and tahmed-dev July 19, 2021 17:23
@lguohan
Copy link
Collaborator

lguohan commented Jul 19, 2021

missing unit test.

Copy link
Contributor

@prsunny prsunny left a comment

Choose a reason for hiding this comment

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

Please provide details of the setting up dhcp chain/acl rule in the description. Need more clarifications on the approach taken.


# Add iptables command to delete all non-default chains
iptables_cmds.append(self.iptables_cmd_ns_prefix[namespace] + "iptables -X")
# Add iptables command to flush the current rules and delete all non-default chains
Copy link
Contributor

Choose a reason for hiding this comment

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

what is this change for?, if caclmgrd restarts, can we flush as before?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is to shield DHCP related rule in separate chain list. When flushing, exclude DHCP chain and flush/delete all other chains other than built-in chains.

Copy link
Author

Choose a reason for hiding this comment

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

yes, if caclmgrd restarts, we flush all.

@@ -383,6 +463,10 @@ class ControlPlaneAclManager(daemon_base.DaemonBase):
iptables_cmds.append(self.iptables_cmd_ns_prefix[namespace] + "ip6tables -A INPUT -p icmpv6 --icmpv6-type router-solicitation -j ACCEPT")
iptables_cmds.append(self.iptables_cmd_ns_prefix[namespace] + "ip6tables -A INPUT -p icmpv6 --icmpv6-type router-advertisement -j ACCEPT")

# Add iptables commands to link the DCHP chain to block dhcp packets based on ingress interfaces
if self.DualToR:
iptables_cmds.append(self.iptables_cmd_ns_prefix[namespace] + "iptables -A INPUT -p udp --dport 67 -j DHCP")
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the below rules required for dualtor? Also why not port 68?

Copy link
Author

Choose a reason for hiding this comment

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

this is to direct matching into DHCP chain, dhcp discovers/requests use dport 67


# Add iptables command to delete all non-default chains
iptables_cmds.append(self.iptables_cmd_ns_prefix[namespace] + "iptables -X")
# Add iptables command to flush the current rules and delete all non-default chains
Copy link
Contributor

Choose a reason for hiding this comment

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

This is to shield DHCP related rule in separate chain list. When flushing, exclude DHCP chain and flush/delete all other chains other than built-in chains.

src/sonic-host-services/scripts/caclmgrd Show resolved Hide resolved
@@ -319,6 +327,77 @@ class ControlPlaneAclManager(daemon_base.DaemonBase):
else:
return False

def setup_dhcp_chain(self, namespace):
all_chains = self.get_chain_list(self.iptables_cmd_ns_prefix[namespace], [""])
dhcp_chain_exist = 1 if "DHCP" in all_chains else 0
Copy link
Contributor

Choose a reason for hiding this comment

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

what about using boolean?
dhcp_chain_exist = "DHCP" in all_chains

Copy link
Author

Choose a reason for hiding this comment

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

updated

@@ -84,6 +86,8 @@ class ControlPlaneAclManager(daemon_base.DaemonBase):

UPDATE_DELAY_SECS = 0.5

DualToR = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

boolean?

Copy link
Author

Choose a reason for hiding this comment

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

updated

@ghost ghost requested review from prsunny and tahmed-dev August 2, 2021 22:45
@ghost
Copy link
Author

ghost commented Aug 3, 2021

retest this please

@ghost
Copy link
Author

ghost commented Aug 3, 2021

/Azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ghost
Copy link
Author

ghost commented Aug 3, 2021

/Azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

tahmed-dev
tahmed-dev previously approved these changes Aug 4, 2021
break
self.log_info("mux cable update : '%s'" % str((key, op, fvs)))
self.update_dhcp_acl(key, op, dict(fvs))
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you confirm this flow is tested on a non-dualtor testbed?

Copy link
Author

@ghost ghost Aug 5, 2021

Choose a reason for hiding this comment

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

yes, i tested it with both subtype=dualtor and none on a vs testbed

@ghost ghost requested a review from prsunny August 5, 2021 20:47
prsunny
prsunny previously approved these changes Aug 6, 2021
@prsunny
Copy link
Contributor

prsunny commented Aug 6, 2021

Is unit test separate PR? or are you planning to add to this?

@prsunny
Copy link
Contributor

prsunny commented Aug 6, 2021

Is unit test separate PR? or are you planning to add to this?

Ok, I see this PR - #8359. You could have it in same PR, FYI

@ghost ghost dismissed stale reviews from prsunny and tahmed-dev via f7c4ad7 August 6, 2021 17:59
@ghost ghost requested review from prsunny and tahmed-dev August 6, 2021 18:01
@ghost
Copy link
Author

ghost commented Aug 7, 2021

/Azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ghost ghost merged commit 8608af7 into sonic-net:master Aug 7, 2021
@ghost ghost deleted the dt_bdr branch August 9, 2021 18:24
ghost pushed a commit that referenced this pull request Aug 16, 2021
caclmgrd: monitor mux_cable_table in state_db to update dhcp acl

- if the state changes to 'standby', add acl to block dhcp packets based on ingress interfaces
- if the state changes to 'active', delete acl
- if the state changes to 'unknown', also delete acl to avoid potential disconnect
- both addition and deletion follow checking the existence of the rules

The change has been verified on a virtual switch based testbed.

Port to 202012 branch from #8222
lguohan pushed a commit that referenced this pull request Sep 14, 2021
Fix #8672

add two missing commits in caclmgrd: monitor state_db to update dhcp acl #8222 when porting to 202012 branch
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants