|
|
@@ -464,6 +464,11 @@ func (m *RoutingManager) ListPolicyRules() []PolicyRuleItem {
|
|
|
tableNames := m.getTableMap()
|
|
|
var res []PolicyRuleItem
|
|
|
|
|
|
+ userRulesByPrio := make(map[int]PolicyRuleItem)
|
|
|
+ for _, pr := range m.policyRules {
|
|
|
+ userRulesByPrio[pr.Priority] = pr
|
|
|
+ }
|
|
|
+
|
|
|
for _, r := range rules {
|
|
|
tableName := "main"
|
|
|
if name, ok := tableNames[r.Table]; ok {
|
|
|
@@ -487,6 +492,24 @@ func (m *RoutingManager) ListPolicyRules() []PolicyRuleItem {
|
|
|
}
|
|
|
|
|
|
id := fmt.Sprintf("rule-%d-%d", r.Priority, r.Table)
|
|
|
+ comment := ""
|
|
|
+ isDefault := false
|
|
|
+ isSystem := false
|
|
|
+
|
|
|
+ if r.Priority == 0 || r.Priority == 32766 || r.Priority == 32767 {
|
|
|
+ isDefault = true
|
|
|
+ isSystem = true
|
|
|
+ } else if userRule, ok := userRulesByPrio[r.Priority]; ok {
|
|
|
+ if userRule.ID != "" {
|
|
|
+ id = userRule.ID
|
|
|
+ }
|
|
|
+ comment = userRule.Comment
|
|
|
+ isDefault = false
|
|
|
+ isSystem = false
|
|
|
+ } else {
|
|
|
+ // System/daemon rule not added by user in proxmox-router (e.g. WireGuard, IPsec)
|
|
|
+ isSystem = true
|
|
|
+ }
|
|
|
|
|
|
res = append(res, PolicyRuleItem{
|
|
|
ID: id,
|
|
|
@@ -497,6 +520,9 @@ func (m *RoutingManager) ListPolicyRules() []PolicyRuleItem {
|
|
|
Table: tableName,
|
|
|
TableID: r.Table,
|
|
|
Action: "lookup",
|
|
|
+ Comment: comment,
|
|
|
+ IsDefault: isDefault,
|
|
|
+ IsSystem: isSystem,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -532,7 +558,7 @@ func (m *RoutingManager) DeletePolicyRule(id string) error {
|
|
|
var updated []PolicyRuleItem
|
|
|
var target *PolicyRuleItem
|
|
|
for _, pr := range m.policyRules {
|
|
|
- if pr.ID == id {
|
|
|
+ if pr.ID == id || fmt.Sprintf("rule-%d-%d", pr.Priority, pr.TableID) == id {
|
|
|
target = &pr
|
|
|
} else {
|
|
|
updated = append(updated, pr)
|
|
|
@@ -541,6 +567,13 @@ func (m *RoutingManager) DeletePolicyRule(id string) error {
|
|
|
|
|
|
if target != nil {
|
|
|
_ = m.removeRuleFromKernel(*target)
|
|
|
+ } else if strings.HasPrefix(id, "rule-") {
|
|
|
+ parts := strings.Split(id, "-")
|
|
|
+ if len(parts) >= 2 {
|
|
|
+ if prio, err := strconv.Atoi(parts[1]); err == nil && prio > 0 {
|
|
|
+ _ = exec.Command("ip", "rule", "del", "pref", strconv.Itoa(prio)).Run()
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
m.policyRules = updated
|
|
|
return m.save()
|
|
|
@@ -578,10 +611,11 @@ func (m *RoutingManager) applyRuleToKernel(pr PolicyRuleItem) error {
|
|
|
}
|
|
|
|
|
|
func (m *RoutingManager) removeRuleFromKernel(pr PolicyRuleItem) error {
|
|
|
- args := []string{"rule", "del"}
|
|
|
if pr.Priority > 0 {
|
|
|
- args = append(args, "pref", strconv.Itoa(pr.Priority))
|
|
|
+ _ = exec.Command("ip", "rule", "del", "pref", strconv.Itoa(pr.Priority)).Run()
|
|
|
+ return nil
|
|
|
}
|
|
|
+ args := []string{"rule", "del"}
|
|
|
if pr.RoutingMark != "" {
|
|
|
markClean := pr.RoutingMark
|
|
|
if strings.Contains(markClean, "(") {
|