// AddRule adds a single rule for an unconditional action on a syscall.
// Accepts the number of the syscall and the action to be taken on the call
// being made.
// Returns an error if an issue was encountered adding the rule.
165768
func (f *ScmpFilter) AddRule(call ScmpSyscall, action ScmpAction) error {
	return f.addRuleGeneric(call, action, false, nil)
}
14586
func (c *ConfigPolicy) AddNewStringRule(ns []string, key string, req bool, opts ...stringRuleOpt) error {
	if key == "" {
		return ErrEmptyKey
	}
	rule := &rpc.StringRule{
		Required: req,
	}

	for _, opt := range opts {
		opt(rule)
	}
	k := strings.Join(ns, ".") // Method used in daemon/ctree
	if c.stringRules[k] == nil {
		c.stringRules[k] = &rpc.StringPolicy{
			Rules: map[string]*rpc.StringRule{},
			Key:   ns,
		}
	}
	c.stringRules[k].Rules[key] = rule
	return nil
}
280263
func NewRule(content string) (*Rule, error) {
	var rule *Rule
	var value string

	switch content[0:1] {
	case "*": // wildcard
		if content == "*" {
			value = ""
		} else {
			value = content[2:]
		}
		rule = &Rule{Type: WildcardType, Value: value, Length: len(Labels(value)) + 1}
	case "!": // exception
		value = content[1:]
		rule = &Rule{Type: ExceptionType, Value: value, Length: len(Labels(value))}
	default: // normal
		value = content
		rule = &Rule{Type: NormalType, Value: value, Length: len(Labels(value))}
	}

	return rule, nil
}
332142
func (s *RuleGroupUpdate) SetActivatedRule(v *ActivatedRule) *RuleGroupUpdate {
	s.ActivatedRule = v
	return s
}
1159107
func newEdns0Rule(mode string, args ...string) (Rule, error) {
	if len(args) < 2 {
		return nil, fmt.Errorf("too few arguments for an EDNS0 rule")
	}

	ruleType := strings.ToLower(args[0])
	action := strings.ToLower(args[1])
	switch action {
	case Append:
	case Replace:
	case Set:
	default:
		return nil, fmt.Errorf("invalid action: %q", action)
	}

	switch ruleType {
	case "local":
		if len(args) != 4 {
			return nil, fmt.Errorf("EDNS0 local rules require exactly three args")
		}
		//Check for variable option
		if strings.HasPrefix(args[3], "{") && strings.HasSuffix(args[3], "}") {
			return newEdns0VariableRule(mode, action, args[2], args[3])
		}
		return newEdns0LocalRule(mode, action, args[2], args[3])
	case "nsid":
		if len(args) != 2 {
			return nil, fmt.Errorf("EDNS0 NSID rules do not accept args")
		}
		return &edns0NsidRule{mode: mode, action: action}, nil
	case "subnet":
		if len(args) != 4 {
			return nil, fmt.Errorf("EDNS0 subnet rules require exactly three args")
		}
		return newEdns0SubnetRule(mode, action, args[2], args[3])
	default:
		return nil, fmt.Errorf("invalid rule type %q", ruleType)
	}
}
1176174
func (si *si) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
	return locales.PluralRuleOther
}
1188204
func (client *Client) SetRule(args *SetRuleArgs) error {
	response := SetRuleResponse{}
	err := client.Invoke("SetRule", args, &response)
	if err != nil {
		return err
	}
	return err
}
265925
func (p *PacketFilter) AddICMPRule(sourceNetwork string, description string, isAllow bool) (*PacketFilterExpression, error) {

	exp := p.createICMPRule(sourceNetwork, description, isAllow)
	p.Expression = append(p.Expression, exp)
	return exp, nil
}
770746
func AddReturnRule(chain string) error {
	var (
		table = Filter
		args  = []string{"-j", "RETURN"}
	)

	if Exists(table, chain, args...) {
		return nil
	}

	err := RawCombinedOutput(append([]string{"-A", chain}, args...)...)
	if err != nil {
		return fmt.Errorf("unable to add return rule in %s chain: %s", chain, err.Error())
	}

	return nil
}
735292
func (s *GetTopicRuleOutput) SetRule(v *TopicRule) *GetTopicRuleOutput {
	s.Rule = v
	return s
}
415073
func (s *CreateRuleOutput) SetRule(v *Rule) *CreateRuleOutput {
	s.Rule = v
	return s
}
193148
func NewRule(p Pos, name *Identifier) *Rule {
	return &Rule{p: p, Name: name}
}
262342
func (r Network_SecurityGroup) AddRules(ruleTemplates []datatypes.Network_SecurityGroup_Rule) (resp datatypes.Network_SecurityGroup_RequestRules, err error) {
	params := []interface{}{
		ruleTemplates,
	}
	err = r.Session.DoRequest("SoftLayer_Network_SecurityGroup", "addRules", params, &r.Options, &resp)
	return
}
426995
func CreateRule(obj *Rule) error {
	// Validate parameters
	err := ValidateRule(obj)
	if err != nil {
		log.Errorf("ValidateRule retruned error for: %+v. Err: %v", obj, err)
		return err
	}

	// Check if we handle this object
	if objCallbackHandler.RuleCb == nil {
		log.Errorf("No callback registered for rule object")
		return errors.New("Invalid object type")
	}

	saveObj := obj

	collections.ruleMutex.Lock()
	key := collections.rules[obj.Key]
	collections.ruleMutex.Unlock()

	// Check if object already exists
	if key != nil {
		// Perform Update callback
		err = objCallbackHandler.RuleCb.RuleUpdate(collections.rules[obj.Key], obj)
		if err != nil {
			log.Errorf("RuleUpdate retruned error for: %+v. Err: %v", obj, err)
			return err
		}

		// save the original object after update
		collections.ruleMutex.Lock()
		saveObj = collections.rules[obj.Key]
		collections.ruleMutex.Unlock()
	} else {
		// save it in cache
		collections.ruleMutex.Lock()
		collections.rules[obj.Key] = obj
		collections.ruleMutex.Unlock()

		// Perform Create callback
		err = objCallbackHandler.RuleCb.RuleCreate(obj)
		if err != nil {
			log.Errorf("RuleCreate retruned error for: %+v. Err: %v", obj, err)
			collections.ruleMutex.Lock()
			delete(collections.rules, obj.Key)
			collections.ruleMutex.Unlock()
			return err
		}
	}

	// Write it to modeldb
	collections.ruleMutex.Lock()
	err = saveObj.Write()
	collections.ruleMutex.Unlock()
	if err != nil {
		log.Errorf("Error saving rule %s to db. Err: %v", saveObj.Key, err)
		return err
	}

	return nil
}
721911
func (g *Cloud) AddRuletoBetaSecurityPolicy(name string, spr *computebeta.SecurityPolicyRule) error {
	ctx, cancel := cloud.ContextWithCallTimeout()
	defer cancel()

	mc := newSecurityPolicyMetricContextWithVersion("add_rule", computeBetaVersion)
	return mc.Observe(g.c.BetaSecurityPolicies().AddRule(ctx, meta.GlobalKey(name), spr))
}
540013
func (s *CreateReceiptRuleInput) SetRule(v *ReceiptRule) *CreateReceiptRuleInput {
	s.Rule = v
	return s
}
727993
func (p *ConfigPolicyNode) Add(rules ...Rule) {
	p.mutex.Lock()
	defer p.mutex.Unlock()
	for _, r := range rules {
		p.rules[r.Key()] = r
	}
}