Browse Source

Upgrade to API version 52

tags/v52
maze 1 year ago
parent
commit
d3c39ef977
7 changed files with 298 additions and 258 deletions
  1. 0
    161
      cmd/filter-rbl/main.go
  2. 172
    0
      cmd/table-rbl/main.go
  3. 13
    13
      filter.go
  4. 2
    2
      filter_test.go
  5. 53
    51
      imsg.go
  6. 16
    12
      smtpd.go
  7. 42
    19
      table.go

+ 0
- 161
cmd/filter-rbl/main.go View File

@@ -1,161 +0,0 @@
package main

import (
"flag"
"fmt"
"log"
"net"
"os"
"strings"

lru "github.com/hashicorp/golang-lru"

"gopkg.in/opensmtpd.v0"
)

var (
prog = os.Args[0]
skip = []*net.IPNet{}
rbls = []string{
"b.barracudacentral.org",
"bl.spamcop.net",
"virbl.bit.nl",
"xbl.spamhaus.org",
}
debug bool
masq bool
cache *lru.Cache
)

func debugf(fmt string, args ...interface{}) {
if !debug {
return
}
log.Printf("debug: "+fmt, args...)
}

func reverse(ip net.IP) string {
if ip.To4() == nil {
return ""
}

splitAddress := strings.Split(ip.String(), ".")

for i, j := 0, len(splitAddress)-1; i < len(splitAddress)/2; i, j = i+1, j-1 {
splitAddress[i], splitAddress[j] = splitAddress[j], splitAddress[i]
}

return strings.Join(splitAddress, ".")
}

func lookup(rbl string, host string) (result string, listed bool, err error) {
host = fmt.Sprintf("%s.%s", host, rbl)

var res []string
res, err = net.LookupHost(host)
if listed = len(res) > 0; listed {
txt, _ := net.LookupTXT(host)
if len(txt) > 0 {
result = txt[0]
}
}

// Expected error
if err != nil && strings.HasSuffix(err.Error(), ": no such host") {
err = nil
}

return
}

func onConnect(s *opensmtpd.Session, query *opensmtpd.ConnectQuery) error {
ip := query.Remote.(opensmtpd.Sockaddr).IP()
if ip == nil {
return nil
}

debugf("%s: connect from %s\n", prog, ip)

for _, ipnet := range skip {
if ipnet.Contains(ip) {
debugf("%s: skip %s, IP ignored", prog, ip)
return s.Accept()
}
}

var (
result string
listed bool
host = reverse(ip)
err error
)
for _, rbl := range rbls {
if result, listed, err = lookup(rbl, host); err != nil {
log.Printf("%s: %s failed %s: %v\n", prog, rbl, ip, err)
} else if listed {
log.Printf("%s: %s listed %s: %v\n", prog, rbl, ip, result)
cache.Add(s.ID, result)
break
}
}

debugf("%s: pass: %s\n", prog, ip)

if !listed {
// Add negative hit
cache.Add(s.ID, "")
}

return s.Accept()
}

func onDATA(s *opensmtpd.Session) error {
debugf("%s: %s DATA\n", prog, s)

if result, block := cache.Get(s.ID); block && result.(string) != "" {
return s.RejectCode(opensmtpd.FilterClose, 421, result.(string))
}

return s.Accept()
}

func main() {
cacheSize := flag.Int("cache-size", 1024, "LRU cache size")
rblServer := flag.String("servers", strings.Join(rbls, ","), "RBL servers")
ignoreIPs := flag.String("ignore", "127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,fe80::/64", "ignore IPs")
debugging := flag.Bool("d", false, "be verbose")
verbosity := flag.Bool("v", false, "be verbose")
flag.BoolVar(&masq, "masq", true, "masquerade SMTP banner")
flag.Parse()

debug = *debugging || *verbosity

var err error
if cache, err = lru.New(*cacheSize); err != nil {
log.Fatalln(err)
}

rbls = strings.Split(*rblServer, ",")

for _, prefix := range strings.Split(*ignoreIPs, ",") {
var ipnet *net.IPNet
if _, ipnet, err = net.ParseCIDR(prefix); err != nil {
log.Fatalln(err)
}
skip = append(skip, ipnet)
debugf("ignore: %s\n", ipnet)
}

filter := &opensmtpd.Filter{
Connect: onConnect,
DATA: onDATA,
}

if err = filter.Register(); err != nil {
log.Fatalln(err)
}

if err = filter.Serve(); err != nil {
log.Fatalln(err)
}
}

+ 172
- 0
cmd/table-rbl/main.go View File

@@ -0,0 +1,172 @@
package main

import (
"flag"
"fmt"
"io/ioutil"
"log"
"net"
"os"
"strings"

lru "github.com/hashicorp/golang-lru"
"github.com/hashicorp/hcl"
opensmtpd "gopkg.in/opensmtpd.v0"
)

var (
cache *lru.Cache
ignored []*net.IPNet
config struct {
Cache int
Ignore []string
Accept []string
Reject []string
}
)

func debugf(format string, args ...interface{}) {
log.Printf("debug: "+format, args...)
}

func update() (int, error) {
log.Println("table-rbl: update")
return 1, nil
}

func reverse(ip net.IP) net.IP {
log.Printf("ip: %#+v", ip)
return net.IP{ip[3], ip[2], ip[1], ip[0]}
}

func lookup(rbl string, host net.IP) (result string, listed bool, err error) {
var (
query = fmt.Sprintf("%s.%s", host, rbl)
results []string
)
log.Printf("table-rbl: lookup %q", query)
if results, err = net.LookupHost(query); err != nil {
if strings.HasSuffix(err.Error(), ": no such host") {
err = nil
}
return
}

if listed = len(results) > 0; listed {
txts, _ := net.LookupTXT(query)
if len(txts) > 0 {
result = txts[0]
}
}
return
}

func check(service int, params opensmtpd.Dict, key string) (int, error) {
log.Printf("table-rbl: check key=%q", key)
if key == "local" {
return 1, nil
}

ips, err := net.LookupIP(key)
if err != nil {
log.Printf("table-rbl: error looking up %q: %v", key, err)
return -1, err
}

for _, ip := range ips {
if ip = ip.To4(); ip == nil {
continue
}
log.Printf("table-rbl: %q resolved to %s (%s)", key, ip, reverse(ip))
for _, network := range ignored {
if network.Contains(ip) {
log.Printf("table-rbl: %s is ignored", ip)
return 1, nil
}
}

if result, block := cache.Get(key); block && result.(string) != "" {
log.Printf("table-rbl: reject %s (reason %q)", ip, result)
return 0, nil
}

var (
result string
listed bool
host = reverse(ip)
err error
)
for _, rbl := range config.Accept {
if result, listed, err = lookup(rbl, host); err != nil {
log.Printf("table-rbl: error looking up %q in %q: %v", host, rbl, err)
return -1, nil
} else if listed {
log.Printf("table-rbl: accept %q (reason %q)", ip, result)
return 1, nil
}
}
for _, rbl := range config.Reject {
if result, listed, err = lookup(rbl, host); err != nil {
log.Printf("table-rbl: error looking up %q in %q: %v", host, rbl, err)
return -1, nil
} else if listed {
log.Printf("table-rbl: reject %q (reason %q)", ip, result)
return 0, nil
}
}
}

log.Printf("table-rbl: accept %q (not rejected)", key)
return 1, nil
}

func main() {
flag.Parse()
if flag.NArg() != 1 {
panic(fmt.Sprintf("%s <config>\n", os.Args[0]))
}
log.Printf("table-rbl: args=%v", flag.Args())

b, err := ioutil.ReadFile(flag.Arg(0))
if err != nil {
log.Fatalln("table-rbl", err)
}
if err = hcl.Unmarshal(b, &config); err != nil {
log.Fatalln("table-rbl", err)
}
if len(config.Reject) == 0 {
log.Fatalln("table-rbl: no reject rules configured")
}

// Setup cache
if config.Cache == 0 {
cache, err = lru.New(1024)
} else {
cache, err = lru.New(config.Cache)
}
if err != nil {
log.Fatalln("table-rbl", err)
}

// Parse ignore rules
for _, prefix := range config.Ignore {
var ipnet *net.IPNet
if _, ipnet, err = net.ParseCIDR(prefix); err != nil {
panic(err)
}
ignored = append(ignored, ipnet)
debugf("ignore %s", ipnet)
}

opensmtpd.Debug = true

table := &opensmtpd.Table{
Update: update,
Check: check,
Close: func() error {
log.Println("table-rbl: close")
return nil
},
}
log.Fatalln(table.Serve())
}

+ 13
- 13
filter.go View File

@@ -178,7 +178,7 @@ type Filter struct {
Version uint32

c net.Conn
m *message
m *Message

hooks int
flags int
@@ -190,7 +190,7 @@ type Filter struct {
func (f *Filter) Register() error {
var err error
if f.m == nil {
f.m = new(message)
f.m = new(Message)
}
if f.c == nil {
if f.c, err = newConn(0); err != nil {
@@ -230,13 +230,13 @@ func (f *Filter) Register() error {
f.hooks |= hookCommit
}

if t, ok := filterTypeName[f.m.Type]; ok {
if t, ok := filterTypeName[f.m.Header.Type]; ok {
log.Printf("filter: imsg %s\n", t)
} else {
log.Printf("filter: imsg UNKNOWN %d\n", f.m.Type)
log.Printf("filter: imsg UNKNOWN %d\n", f.m.Header.Type)
}

switch f.m.Type {
switch f.m.Header.Type {
case typeFilterRegister:
var err error
if f.Version, err = f.m.GetTypeUint32(); err != nil {
@@ -248,14 +248,14 @@ func (f *Filter) Register() error {
log.Printf("register version=%d,name=%q\n", f.Version, f.Name)

f.m.reset()
f.m.Type = typeFilterRegister
f.m.Header.Type = typeFilterRegister
f.m.PutTypeInt(f.hooks)
f.m.PutTypeInt(f.flags)
if err = f.m.WriteTo(f.c); err != nil {
return err
}
default:
return fmt.Errorf("filter: unexpected imsg type=%s\n", filterTypeName[f.m.Type])
return fmt.Errorf("filter: unexpected imsg type=%s\n", filterTypeName[f.m.Header.Type])
}

f.ready = true
@@ -274,7 +274,7 @@ func (f *Filter) Serve() error {
}

if f.m == nil {
f.m = new(message)
f.m = new(Message)
}
if f.session == nil {
if f.session, err = lru.New(1024); err != nil {
@@ -300,13 +300,13 @@ func (f *Filter) Serve() error {
}

func (f *Filter) handle() (err error) {
if t, ok := filterTypeName[f.m.Type]; ok {
if t, ok := filterTypeName[f.m.Header.Type]; ok {
log.Printf("filter: imsg %s\n", t)
} else {
log.Printf("filter: imsg UNKNOWN %d\n", f.m.Type)
log.Printf("filter: imsg UNKNOWN %d\n", f.m.Header.Type)
}

switch f.m.Type {
switch f.m.Header.Type {
case typeFilterEvent:
if err = f.handleEvent(); err != nil {
return
@@ -488,8 +488,8 @@ func (f *Filter) respond(s *Session, status, code int, line string) error {
return nil
}

m := new(message)
m.Type = typeFilterResponse
m := new(Message)
m.Header.Type = typeFilterResponse
m.PutTypeID(s.qid)
m.PutTypeInt(s.qtype)
if s.qtype == queryEOM {

+ 2
- 2
filter_test.go View File

@@ -7,7 +7,7 @@ func ExampleFilter() {
filter := &Filter{
HELO: func(session *Session, helo string) error {
if helo == "test" {
return session.Reject()
return session.Reject(FilterOK, 0)
}
return session.Accept()
},
@@ -16,7 +16,7 @@ func ExampleFilter() {
// Add another hook
filter.MAIL = func(session *Session, user, domain string) error {
if strings.ToLower(domain) == "example.org" {
return session.Reject()
return session.Reject(FilterOK, 0)
}
return session.Accept()
}

+ 53
- 51
imsg.go View File

@@ -20,8 +20,8 @@ const (
maxDomainPartSize = (255 + 1)
)

// messageHeader is the header of an imsg frame (struct imsg_hdr)
type messageHeader struct {
// MessageHeader is the header of an imsg frame (struct imsg_hdr)
type MessageHeader struct {
Type uint32
Len uint16
Flags uint16
@@ -30,8 +30,10 @@ type messageHeader struct {
}

// message implements OpenBSD imsg
type message struct {
messageHeader
type Message struct {
Header MessageHeader

// Data is the Message payload.
Data []byte

// rpos is the read position in the current Data
@@ -41,12 +43,12 @@ type message struct {
buf []byte
}

func (m *message) reset() {
m.Type = 0
m.Len = 0
m.Flags = 0
m.PeerID = imsgVersion
m.PID = uint32(os.Getpid())
func (m *Message) reset() {
m.Header.Type = 0
m.Header.Len = 0
m.Header.Flags = 0
m.Header.PeerID = imsgVersion
m.Header.PID = uint32(os.Getpid())
m.Data = m.Data[:0]
m.rpos = 0
m.buf = m.buf[:0]
@@ -54,22 +56,22 @@ func (m *message) reset() {

// ReadFrom reads a message from the specified net.Conn, parses the header and
// reads the data payload.
func (m *message) ReadFrom(c net.Conn) error {
func (m *Message) ReadFrom(r io.Reader) error {
m.reset()

head := make([]byte, imsgHeaderSize)
if _, err := c.Read(head); err != nil {
if _, err := r.Read(head); err != nil {
return err
}

r := bytes.NewBuffer(head)
if err := binary.Read(r, binary.LittleEndian, &m.messageHeader); err != nil {
buf := bytes.NewBuffer(head)
if err := binary.Read(buf, binary.LittleEndian, &m.Header); err != nil {
return err
}
debugf("imsg header: %+v\n", m.messageHeader)
debugf("imsg header: %+v\n", m.Header)

data := make([]byte, m.messageHeader.Len-imsgHeaderSize)
if _, err := c.Read(data); err != nil {
data := make([]byte, m.Header.Len-imsgHeaderSize)
if _, err := r.Read(data); err != nil {
return err
}
m.Data = data
@@ -79,22 +81,22 @@ func (m *message) ReadFrom(c net.Conn) error {
}

// WriteTo marshals the message to wire format and sends it to the net.Conn
func (m *message) WriteTo(c net.Conn) error {
m.Len = uint16(len(m.Data)) + imsgHeaderSize
func (m *Message) WriteTo(w io.Writer) error {
m.Header.Len = uint16(len(m.Data)) + imsgHeaderSize

buf := new(bytes.Buffer)
debugf("imsg header: %+v\n", m.messageHeader)
if err := binary.Write(buf, binary.LittleEndian, &m.messageHeader); err != nil {
debugf("imsg header: %+v\n", m.Header)
if err := binary.Write(buf, binary.LittleEndian, &m.Header); err != nil {
return err
}
buf.Write(m.Data)
debugf("imsg send: %d / %q\n", buf.Len(), buf.Bytes())

_, err := c.Write(buf.Bytes())
_, err := w.Write(buf.Bytes())
return err
}

func (m *message) GetInt() (int, error) {
func (m *Message) GetInt() (int, error) {
if m.rpos+4 > len(m.Data) {
return 0, io.ErrShortBuffer
}
@@ -103,7 +105,7 @@ func (m *message) GetInt() (int, error) {
return int(i), nil
}

func (m *message) GetUint32() (uint32, error) {
func (m *Message) GetUint32() (uint32, error) {
if m.rpos+4 > len(m.Data) {
return 0, io.ErrShortBuffer
}
@@ -112,7 +114,7 @@ func (m *message) GetUint32() (uint32, error) {
return u, nil
}

func (m *message) GetSize() (uint64, error) {
func (m *Message) GetSize() (uint64, error) {
if m.rpos+8 > len(m.Data) {
return 0, io.ErrShortBuffer
}
@@ -121,7 +123,7 @@ func (m *message) GetSize() (uint64, error) {
return u, nil
}

func (m *message) GetString() (string, error) {
func (m *Message) GetString() (string, error) {
o := bytes.IndexByte(m.Data[m.rpos:], 0)
if o < 0 {
return "", errors.New("imsg: string not NULL-terminated")
@@ -132,7 +134,7 @@ func (m *message) GetString() (string, error) {
return s, nil
}

func (m *message) GetID() (uint64, error) {
func (m *Message) GetID() (uint64, error) {
if m.rpos+8 > len(m.Data) {
return 0, io.ErrShortBuffer
}
@@ -174,7 +176,7 @@ func (sa Sockaddr) String() string {
return fmt.Sprintf("%s:%d", sa.IP(), sa.Port())
}

func (m *message) GetSockaddr() (net.Addr, error) {
func (m *Message) GetSockaddr() (net.Addr, error) {
s, err := m.GetSize()
if err != nil {
return nil, err
@@ -190,7 +192,7 @@ func (m *message) GetSockaddr() (net.Addr, error) {
return a, nil
}

func (m *message) GetMailaddr() (user, domain string, err error) {
func (m *Message) GetMailaddr() (user, domain string, err error) {
var buf [maxLocalPartSize + maxDomainPartSize]byte
if maxLocalPartSize+maxDomainPartSize > len(m.Data[m.rpos:]) {
return "", "", io.ErrShortBuffer
@@ -202,7 +204,7 @@ func (m *message) GetMailaddr() (user, domain string, err error) {
return
}

func (m *message) GetType(t uint8) error {
func (m *Message) GetType(t uint8) error {
if m.rpos >= len(m.Data) {
return io.ErrShortBuffer
}
@@ -215,102 +217,102 @@ func (m *message) GetType(t uint8) error {
return nil
}

func (m *message) GetTypeInt() (int, error) {
func (m *Message) GetTypeInt() (int, error) {
if err := m.GetType(mINT); err != nil {
return 0, err
}
return m.GetInt()
}

func (m *message) GetTypeUint32() (uint32, error) {
func (m *Message) GetTypeUint32() (uint32, error) {
if err := m.GetType(mUINT32); err != nil {
return 0, err
}
return m.GetUint32()
}

func (m *message) GetTypeSize() (uint64, error) {
func (m *Message) GetTypeSize() (uint64, error) {
if err := m.GetType(mSIZET); err != nil {
return 0, err
}
return m.GetSize()
}

func (m *message) GetTypeString() (string, error) {
func (m *Message) GetTypeString() (string, error) {
if err := m.GetType(mSTRING); err != nil {
return "", err
}
return m.GetString()
}

func (m *message) GetTypeID() (uint64, error) {
func (m *Message) GetTypeID() (uint64, error) {
if err := m.GetType(mID); err != nil {
return 0, err
}
return m.GetID()
}

func (m *message) GetTypeSockaddr() (net.Addr, error) {
func (m *Message) GetTypeSockaddr() (net.Addr, error) {
if err := m.GetType(mSOCKADDR); err != nil {
return nil, err
}
return m.GetSockaddr()
}

func (m *message) GetTypeMailaddr() (user, domain string, err error) {
func (m *Message) GetTypeMailaddr() (user, domain string, err error) {
if err = m.GetType(mMAILADDR); err != nil {
return
}
return m.GetMailaddr()
}

func (m *message) PutInt(v int) {
func (m *Message) PutInt(v int) {
var b [4]byte
binary.LittleEndian.PutUint32(b[:], uint32(v))
m.Data = append(m.Data, b[:]...)
m.Len += 4
m.Header.Len += 4
}

func (m *message) PutUint32(v uint32) {
func (m *Message) PutUint32(v uint32) {
var b [4]byte
binary.LittleEndian.PutUint32(b[:], v)
m.Data = append(m.Data, b[:]...)
m.Len += 4
m.Header.Len += 4
}

func (m *message) PutString(s string) {
func (m *Message) PutString(s string) {
m.Data = append(m.Data, append([]byte(s), 0)...)
m.Len += uint16(len(s)) + 1
m.Header.Len += uint16(len(s)) + 1
}

func (m *message) PutID(id uint64) {
func (m *Message) PutID(id uint64) {
var b [8]byte
binary.LittleEndian.PutUint64(b[:], id)
m.Data = append(m.Data, b[:]...)
m.Len += 8
m.Header.Len += 8
}

func (m *message) PutType(t uint8) {
func (m *Message) PutType(t uint8) {
m.Data = append(m.Data, t)
m.Len += 1
m.Header.Len += 1
}

func (m *message) PutTypeInt(v int) {
func (m *Message) PutTypeInt(v int) {
m.PutType(mINT)
m.PutInt(v)
}

func (m *message) PutTypeUint32(v uint32) {
func (m *Message) PutTypeUint32(v uint32) {
m.PutType(mUINT32)
m.PutUint32(v)
}

func (m *message) PutTypeString(s string) {
func (m *Message) PutTypeString(s string) {
m.PutType(mSTRING)
m.PutString(s)
}

func (m *message) PutTypeID(id uint64) {
func (m *Message) PutTypeID(id uint64) {
m.PutType(mID)
m.PutID(id)
}

+ 16
- 12
smtpd.go View File

@@ -8,13 +8,13 @@ import (

const (
// FilterVersion is the supported filter API version
FilterVersion = 51
FilterVersion = 52

// QueueVersion is the supported queue API version
QueueVersion = 1
QueueVersion = 2

// TableVersion is the supported table API version
TableVersion = 1
TableVersion = 2
)

var (
@@ -36,19 +36,23 @@ const (
ServiceMailaddr = 0x040
ServiceAddrname = 0x080
ServiceMailaddrMap = 0x100
ServiceRelayHost = 0x200
ServiceString = 0x400
ServiceAny = 0xfff
)

var serviceTypeName = map[int]string{
ServiceAlias: "ALIAS",
ServiceDomain: "DOMAIN",
ServiceCredentials: "CREDENTIALS",
ServiceNetaddr: "NETADDR",
ServiceUserinfo: "USERINFO",
ServiceSource: "SOURCE",
ServiceMailaddr: "MAILADDR",
ServiceAddrname: "ADDRNAME",
ServiceMailaddrMap: "MAILADDRMAP",
ServiceAlias: "alias",
ServiceDomain: "domain",
ServiceCredentials: "credentials",
ServiceNetaddr: "netaddr",
ServiceUserinfo: "userinfo",
ServiceSource: "source",
ServiceMailaddr: "mailaddr",
ServiceAddrname: "addrname",
ServiceMailaddrMap: "maddrmap",
ServiceRelayHost: "relayhost",
ServiceString: "string",
}

func serviceName(service int) string {

+ 42
- 19
table.go View File

@@ -39,6 +39,21 @@ func procTableName(t uint32) string {
return fmt.Sprintf("UNKNOWN %d", t)
}

// Table services.
const (
TableAlias = 0x001 /* returns struct expand */
TableDomain = 0x002 /* returns struct destination */
TableCredentials = 0x004 /* returns struct credentials */
TableNetAddr = 0x008 /* returns struct netaddr */
TableUserInfo = 0x010 /* returns struct userinfo */
TableSource = 0x020 /* returns struct source */
TableMailAddr = 0x040 /* returns struct mailaddr */
TableAddrName = 0x080 /* returns struct addrname */
TableMailAddrMap = 0x100 /* returns struct maddrmap */
TableRelayHost = 0x200 /* returns struct relayhost */
TableString = 0x400
)

// Table implements the OpenSMTPD table API
type Table struct {
// Update callback
@@ -57,7 +72,7 @@ type Table struct {
Close func() error

c net.Conn
m *message
m *Message
closed bool
}

@@ -68,17 +83,17 @@ func (t *Table) Serve() error {
return err
}

t.m = new(message)
t.m = new(Message)

for !t.closed {
if err = t.m.ReadFrom(t.c); err != nil {
if err.Error() != "resource temporarily unavailable" {
break
return fmt.Errorf("read error: %v", err)
}
}
debugf("table: %s", procTableName(t.m.Type))
debugf("table: %s", procTableName(t.m.Header.Type))
if err = t.dispatch(); err != nil {
break
return fmt.Errorf("dispatch error: %v", err)
}
}

@@ -91,7 +106,7 @@ type tableOpenParams struct {
}

func (t *Table) dispatch() (err error) {
switch t.m.Type {
switch t.m.Header.Type {
case procTableOpen:
/*
var op tableOpenParams
@@ -120,12 +135,12 @@ func (t *Table) dispatch() (err error) {
fatal("table: no name supplied by smtpd!?")
}

debugf("table: version=%d,name=%q\n", version, name)
debugf("table: version=%d name=%q\n", version, name)

m := new(message)
m.Type = procTableOK
m.Len = imsgHeaderSize
m.PID = uint32(os.Getpid())
m := new(Message)
m.Header.Type = procTableOK
m.Header.Len = imsgHeaderSize
m.Header.PID = uint32(os.Getpid())
if err = m.WriteTo(t.c); err != nil {
return
}
@@ -139,8 +154,8 @@ func (t *Table) dispatch() (err error) {
}
}

m := new(message)
m.Type = procTableOK
m := new(Message)
m.Header.Type = procTableOK
m.PutInt(r)
if err = m.WriteTo(t.c); err != nil {
return
@@ -184,6 +199,14 @@ func (t *Table) dispatch() (err error) {

log.Printf("table_check: result=%d\n", r)

m := new(Message)
m.Header.Type = procTableOK
m.Header.PID = uint32(os.Getpid())
m.PutInt(r)
if err = m.WriteTo(t.c); err != nil {
return
}

case procTableLookup:
var service int
if service, err = t.m.GetInt(); err != nil {
@@ -210,9 +233,9 @@ func (t *Table) dispatch() (err error) {
}
}

m := new(message)
m.Type = procTableOK
m.PID = uint32(os.Getpid())
m := new(Message)
m.Header.Type = procTableOK
m.Header.PID = uint32(os.Getpid())
if val == "" {
m.PutInt(-1)
} else {
@@ -244,9 +267,9 @@ func (t *Table) dispatch() (err error) {
}
}

m := new(message)
m.Type = procTableOK
m.PID = uint32(os.Getpid())
m := new(Message)
m.Header.Type = procTableOK
m.Header.PID = uint32(os.Getpid())
if val == "" {
m.PutInt(-1)
} else {

Loading…
Cancel
Save