Skip to content

Commit

Permalink
feat: support vtap_group_ids in npb_policy
Browse files Browse the repository at this point in the history
  • Loading branch information
SongZhen0704 authored and ZhengYa-0110 committed Jan 20, 2025
1 parent e6753f7 commit ff69cd5
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 48 deletions.
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

0 comments on commit ff69cd5

Please sign in to comment.