smcroute

package module
v0.0.0-...-b57b150 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2020 License: MIT Imports: 11 Imported by: 0

README

Smcroute

GoDoc Coverage Status Go Report Card

Smcroute is client library for smcroute written in Go programming language.

Library uses unix domain socket for communication.

Tested with smcroute@v2.0.0 and smcroute@v2.4.4.

Quick-start

$ sudo chmod 777 /var/run/smcroute
package main

import (
  "fmt"

  "github.com/go-x-pkg/smcroute"
)

// sudo smcroute -j eth0.1 239.255.1.1
func main() {
  client := smcroute.NewClient()
  cmdJoin := smcroute.NewCmd(smcroute.CmdJoin, "eth0.1", "239.255.1.1")
  resp, err := client.Exec(cmdJoin)
  fmt.Println(resp, err)
}

Join and leave

$ sudo chmod 777 /var/run/smcroute
$ ip maddr show eth0.1
2:      eth0.1
        link  33:33:00:00:00:01
        link  01:00:5e:00:00:01
        link  33:33:ff:93:e9:07
        link  33:33:00:00:02:02
        inet  224.0.0.1
        inet6 ff02::202
        inet6 ff02::1:ff93:e907
        inet6 ff02::1
        inet6 ff01::1
package main

import (
  "fmt"

  "github.com/go-x-pkg/smcroute"
)

// sudo smcroute -j eth0.1 239.255.1.1
func main() {
  client := smcroute.NewClient()
  cmdJoin := smcroute.NewCmd(smcroute.CmdJoin, "eth0.1", "239.255.1.1")
  resp, err := client.Exec(cmdJoin)
  fmt.Println(resp, err)
}
$ ip maddr show eth0.1
2:      eth0.1
        link  33:33:00:00:00:01
        link  01:00:5e:00:00:01
        link  33:33:ff:93:e9:07
        link  33:33:00:00:02:02
        inet  224.0.0.1
        inet  239.255.1.1        # <--- +1
        inet6 ff02::202
        inet6 ff02::1:ff93:e907
        inet6 ff02::1
        inet6 ff01::1
package main

import (
  "fmt"

  "github.com/go-x-pkg/smcroute"
)

// sudo smcroute -l eth0.1 239.255.1.1
func main() {
  client := smcroute.NewClient()
  cmdLeave := smcroute.NewCmd(smcroute.CmdLeave, "eth0.1", "239.255.1.1")
  resp, e := client.Exec(cmdLeave)
  fmt.Println(resp, e)
}
$ ip maddr show eth0.1
2:      eth0.1
        link  33:33:00:00:00:01
        link  01:00:5e:00:00:01
        link  33:33:ff:93:e9:07
        link  33:33:00:00:02:02
        inet  224.0.0.1
        inet6 ff02::202
        inet6 ff02::1:ff93:e907
        inet6 ff02::1
        inet6 ff01::1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output.

func FlushLog

func FlushLog()

Call this before app shutdown

func MessageCodeString

func MessageCodeString(mc MessageCode) string

func MessageCodeText

func MessageCodeText(mc MessageCode) string

func NewMessageInitialize

func NewMessageInitialize(it *Message)

func SetLogWriter

func SetLogWriter(writer io.Writer) error

SetLogWriter uses a specified io.Writer to output library log. Use this func if you are not using Seelog logging system in your app.

func UseLogger

func UseLogger(newLogger seelog.LoggerInterface)

UseLogger uses a specified seelog.LoggerInterface to output library log. Use this func if you are using Seelog logging system in your app.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient() *Client

func (*Client) Conn

func (c *Client) Conn() (net.Conn, *Message)

func (*Client) Exec

func (c *Client) Exec(cmd *Cmd) (*bytes.Buffer, *Message)

func (*Client) SetSocketPath

func (c *Client) SetSocketPath(v string) *Client

type Cmd

type Cmd struct {
	// contains filtered or unexported fields
}

func NewCmd

func NewCmd(cmdKind CmdKind, args ...string) *Cmd

func (*Cmd) Encode

func (cmd *Cmd) Encode() (*bytes.Buffer, error)

-j eth0.33 239.255.11.101

+----+-----+---+-------------------------------+
| 40 | 'j' | 2 | "eth0.33\0239.255.11.101\0\0" |
+----+-----+---+-------------------------------+
^              ^
|              |
|              |
+-----cmd------+

sizeof(struct cmd) = 16
strlen(args) = 21
sizeof(3 NULL_CHARACTERS) = 3
  2 => after each string arument
  1 => at the end of arfs bye array

length = 16 + 21 + 3 = 40 bytes

strace: write(3, "(\0\0\0\0\0\0\0j\0\2\0\0\0\0\0eth0.33\000239.255.11.101\0\0", 40) = 40

func (*Cmd) StringBash

func (cmd *Cmd) StringBash() string

type CmdKind

type CmdKind uint16
const (
	CmdUnknown CmdKind = 0
	CmdJoin    CmdKind = 'j' // Join a multicast group
	CmdLeave   CmdKind = 'l' // Leave a multicast group
	CmdAdd     CmdKind = 'a' // Add a multicast route
	CmdRemove  CmdKind = 'r' // Remove a multicast route
)

func (CmdKind) String

func (ck CmdKind) String() string

type Message

type Message struct {
	Code MessageCode `json:"code,omitempty" yaml:"code"`
	Text string      `json:"text,omitempty" yaml:"text"`
}

func Errorf

func Errorf(code MessageCode, params ...interface{}) *Message

func NewMessage

func NewMessage() *Message

func (*Message) Error

func (msg *Message) Error() string

func (*Message) GetCode

func (msg *Message) GetCode() MessageCode

func (*Message) GetText

func (msg *Message) GetText() string

func (*Message) Is

func (msg *Message) Is(code MessageCode) bool

func (*Message) SetCode

func (msg *Message) SetCode(v MessageCode) *Message

func (*Message) SetText

func (msg *Message) SetText(v string) *Message

func (*Message) String

func (msg *Message) String() string

type MessageCode

type MessageCode uint16
const (
	MessageUnknown MessageCode = 0

	Info  MessageCode = 0x8000
	Error MessageCode = 0x4000
)
const (
	InfoOkJoin MessageCode = Info | iota
	InfoOkLeave
)
const (
	ErrorSocketConnect MessageCode = Error | iota
	ErrorSocketWrite
	ErrorSocketRead
	ErrorCmdEncode
	ErrorExec
	ErrorDropMembershipFailed99
	ErrorFailedLeaveNotAMember
)

func (MessageCode) String

func (mc MessageCode) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL