mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-25 03:34:58 +00:00
vsudd: Use RFC5425 scheme for syslog forwarding
This means an ASCII MSG-LEN and a space, rather than a binary message length. Signed-off-by: Ian Campbell <ian.campbell@docker.com>
This commit is contained in:
parent
916d920bfb
commit
43e2030e31
@ -7,8 +7,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
@ -37,11 +37,12 @@ var (
|
|||||||
lastMessage []byte
|
lastMessage []byte
|
||||||
)
|
)
|
||||||
|
|
||||||
func checkedWrite(conn vConn, buf []byte) error {
|
/* rfc5425 like scheme, see section 4.3 */
|
||||||
|
func rfc5425Write(conn vConn, buf []byte) error {
|
||||||
|
|
||||||
var l uint32 = uint32(len(buf))
|
msglen := fmt.Sprintf("%d ", len(buf))
|
||||||
|
|
||||||
err := binary.Write(conn, binary.LittleEndian, l)
|
_, err := conn.Write([]byte(msglen))
|
||||||
/* XXX todo, check for serious vs retriable errors */
|
/* XXX todo, check for serious vs retriable errors */
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Printf("Error in length write: %s", err)
|
console.Printf("Error in length write: %s", err)
|
||||||
@ -98,7 +99,7 @@ func forwardSyslogDatagram(buf []byte, portstr string) error {
|
|||||||
|
|
||||||
if lastMessage != nil {
|
if lastMessage != nil {
|
||||||
console.Printf("Replaying last message: %s", lastMessage)
|
console.Printf("Replaying last message: %s", lastMessage)
|
||||||
err := checkedWrite(conn, lastMessage)
|
err := rfc5425Write(conn, lastMessage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
conn.Close()
|
conn.Close()
|
||||||
continue
|
continue
|
||||||
@ -109,7 +110,7 @@ func forwardSyslogDatagram(buf []byte, portstr string) error {
|
|||||||
currentConn = conn
|
currentConn = conn
|
||||||
}
|
}
|
||||||
|
|
||||||
err := checkedWrite(conn, buf)
|
err := rfc5425Write(conn, buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
currentConn.Close()
|
currentConn.Close()
|
||||||
currentConn = nil
|
currentConn = nil
|
||||||
|
Loading…
Reference in New Issue
Block a user