| // Copyright 2018 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| // +build !build_with_native_toolchain |
| |
| package filter |
| |
| import ( |
| "syscall/zx" |
| "syscall/zx/fidl" |
| |
| "go.fuchsia.dev/fuchsia/src/lib/component" |
| syslog "go.fuchsia.dev/fuchsia/src/lib/syslog/go" |
| |
| "fidl/fuchsia/net/filter" |
| ) |
| |
| type filterImpl struct { |
| filter *Filter |
| } |
| |
| func AddOutgoingService(ctx *component.Context, f *Filter) { |
| stub := filter.FilterWithCtxStub{Impl: &filterImpl{filter: f}} |
| ctx.OutgoingService.AddService( |
| filter.FilterName, |
| func(ctx fidl.Context, c zx.Channel) error { |
| go component.ServeExclusive(ctx, &stub, c, func(err error) { |
| _ = syslog.WarnTf(tag, "%s", err) |
| }) |
| return nil |
| }, |
| ) |
| } |
| |
| func (f *filterImpl) Enable(_ fidl.Context, v bool) (filter.Status, error) { |
| f.filter.setEnabled(v) |
| return f.filter.setEnabled(v), nil |
| } |
| |
| func (f *filterImpl) IsEnabled(fidl.Context) (bool, error) { |
| return f.filter.enabled(), nil |
| } |
| |
| func (f *filterImpl) GetRules(fidl.Context) ([]filter.Rule, uint32, filter.Status, error) { |
| rules, generation := f.filter.lastRules() |
| return rules, generation, filter.StatusOk, nil |
| } |
| |
| func (f *filterImpl) UpdateRules(_ fidl.Context, nrs []filter.Rule, generation uint32) (filter.Status, error) { |
| return f.filter.updateRules(nrs, generation), nil |
| } |
| |
| func (*filterImpl) GetNatRules(fidl.Context) ([]filter.Nat, uint32, filter.Status, error) { |
| return nil, 1, filter.StatusOk, nil |
| } |
| |
| func (*filterImpl) UpdateNatRules(fidl.Context, []filter.Nat, uint32) (filter.Status, error) { |
| return filter.StatusErrNotSupported, nil |
| } |
| |
| func (*filterImpl) GetRdrRules(fidl.Context) ([]filter.Rdr, uint32, filter.Status, error) { |
| return nil, 1, filter.StatusOk, nil |
| } |
| |
| func (*filterImpl) UpdateRdrRules(fidl.Context, []filter.Rdr, uint32) (filter.Status, error) { |
| return filter.StatusErrNotSupported, nil |
| } |