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

feat: support vtap_group_ids in npb_policy #8966

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 30 additions & 24 deletions server/controller/trisolaris/metadata/agentmetadata/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,34 +617,40 @@ func (op *PolicyDataOP) generateProtoActions(acl *models.ACL) (map[int][]*agent.
NpbAclGroupId: proto.Uint32(uint32(npbPolicy.PolicyACLGroupID)),
Direction: &direction,
}
switch npbPolicy.VtapType {
case POLICY_VTAP_TYPE_VTAP:
for _, agentIDStr := range strings.Split(npbPolicy.VtapIDs, ",") {
agentIDInt, err := strconv.Atoi(agentIDStr)
if err != nil {
log.Errorf(op.Logf("err: %s, agentIDs: %s", err, npbPolicy.VtapIDs))
continue

if npbPolicy.VtapType == POLICY_VTAP_TYPE_VTAP {
if len(npbPolicy.VtapIDs) == 0 {
allAgentNpbActions = append(allAgentNpbActions, npbAction)
} else {
for _, agentIDStr := range strings.Split(npbPolicy.VtapIDs, ",") {
agentIDInt, err := strconv.Atoi(agentIDStr)
if err != nil {
log.Errorf(op.Logf("err: %s, agentIDs: %s", err, npbPolicy.VtapIDs))
continue
}
agentIDToNpbActions[agentIDInt] = append(agentIDToNpbActions[agentIDInt], npbAction)
}
agentIDToNpbActions[agentIDInt] = append(agentIDToNpbActions[agentIDInt], npbAction)
}
case POLICY_VTAP_TYPE_VTAP_GROUP:
for _, vtapGroupIDStr := range strings.Split(npbPolicy.VtapGroupIDs, ",") {
vtapGroupIDInt, err := strconv.Atoi(vtapGroupIDStr)
if err != nil {
log.Errorf(op.Logf("err: %s, vtapGroupIDs: %s", err, npbPolicy.VtapGroupIDs))
continue
}
agentIDs, ok := rawData.vtapGroupIDToAgentIDs[vtapGroupIDInt]
if !ok {
log.Errorf(op.Logf("not found agent in vtap group id(%d)", vtapGroupIDInt))
continue
}
for agentID := range agentIDs {
agentIDToNpbActions[agentID] = append(agentIDToNpbActions[agentID], npbAction)
} else {
if len(npbPolicy.VtapGroupIDs) == 0 {
allAgentNpbActions = append(allAgentNpbActions, npbAction)
} else {
for _, vtapGroupIDStr := range strings.Split(npbPolicy.VtapGroupIDs, ",") {
vtapGroupIDInt, err := strconv.Atoi(vtapGroupIDStr)
if err != nil {
log.Errorf(op.Logf("err: %s, vtapGroupIDs: %s", err, npbPolicy.VtapGroupIDs))
continue
}
agentIDs, ok := rawData.vtapGroupIDToAgentIDs[vtapGroupIDInt]
if !ok {
log.Errorf(op.Logf("not found agent in vtap group id(%d)", vtapGroupIDInt))
continue
}
for agentID := range agentIDs {
agentIDToNpbActions[agentID] = append(agentIDToNpbActions[agentID], npbAction)
}
}
}
default:
allAgentNpbActions = append(allAgentNpbActions, npbAction)
}
}
case APPLICATION_PCAP:
Expand Down
53 changes: 29 additions & 24 deletions server/controller/trisolaris/metadata/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,34 +641,39 @@ func (op *PolicyDataOP) generateProtoActions(acl *models.ACL) (map[int][]*triden
Direction: &direction,
}

switch npbPolicy.VtapType {
case POLICY_VTAP_TYPE_VTAP:
for _, vtapIDStr := range strings.Split(npbPolicy.VtapIDs, ",") {
vtapIDInt, err := strconv.Atoi(vtapIDStr)
if err != nil {
log.Errorf(op.Logf("err: %s, vtapIDs: %s", err, npbPolicy.VtapIDs))
continue
if npbPolicy.VtapType == POLICY_VTAP_TYPE_VTAP {
if len(npbPolicy.VtapIDs) == 0 {
allVTapNpbActions = append(allVTapNpbActions, npbAction)
} else {
for _, vtapIDStr := range strings.Split(npbPolicy.VtapIDs, ",") {
vtapIDInt, err := strconv.Atoi(vtapIDStr)
if err != nil {
log.Errorf(op.Logf("err: %s, vtapIDs: %s", err, npbPolicy.VtapIDs))
continue
}
vtapIDToNpbActions[vtapIDInt] = append(vtapIDToNpbActions[vtapIDInt], npbAction)
}
vtapIDToNpbActions[vtapIDInt] = append(vtapIDToNpbActions[vtapIDInt], npbAction)
}
case POLICY_VTAP_TYPE_VTAP_GROUP:
for _, vtapGroupIDStr := range strings.Split(npbPolicy.VtapGroupIDs, ",") {
vtapGroupIDInt, err := strconv.Atoi(vtapGroupIDStr)
if err != nil {
log.Errorf(op.Logf("err: %s, vtapGroupIDs: %s", err, npbPolicy.VtapGroupIDs))
continue
}
vtapIDs, ok := rawData.vtapGroupIDToVtapIDs[vtapGroupIDInt]
if !ok {
log.Errorf(op.Logf("not found vtap in vtap group id(%d)", vtapGroupIDInt))
continue
}
for vtapID := range vtapIDs {
vtapIDToNpbActions[vtapID] = append(vtapIDToNpbActions[vtapID], npbAction)
} else {
if len(npbPolicy.VtapGroupIDs) == 0 {
allVTapNpbActions = append(allVTapNpbActions, npbAction)
} else {
for _, vtapGroupIDStr := range strings.Split(npbPolicy.VtapGroupIDs, ",") {
vtapGroupIDInt, err := strconv.Atoi(vtapGroupIDStr)
if err != nil {
log.Errorf(op.Logf("err: %s, vtapGroupIDs: %s", err, npbPolicy.VtapGroupIDs))
continue
}
vtapIDs, ok := rawData.vtapGroupIDToVtapIDs[vtapGroupIDInt]
if !ok {
log.Errorf(op.Logf("not found vtap in vtap group id(%d)", vtapGroupIDInt))
continue
}
for _, vtapID := range vtapIDs {
vtapIDToNpbActions[vtapID] = append(vtapIDToNpbActions[vtapID], npbAction)
}
}
}
default:
allVTapNpbActions = append(allVTapNpbActions, npbAction)
}
}
case APPLICATION_PCAP:
Expand Down
Loading