- Use log(9) instead of printf(9).

- Print node ID, where possible.
- Prepend log messages with function name, or at least with "ng_pppoe".

Reviewed by:	julian
Tested by:	Joao Barros <joao.barros gmail.com>
This commit is contained in:
Gleb Smirnoff 2006-08-07 08:05:10 +00:00
parent 03335ffbe9
commit 2e87c3cc4d

View File

@ -48,6 +48,7 @@
#include <sys/mbuf.h> #include <sys/mbuf.h>
#include <sys/malloc.h> #include <sys/malloc.h>
#include <sys/errno.h> #include <sys/errno.h>
#include <sys/syslog.h>
#include <net/ethernet.h> #include <net/ethernet.h>
#include <netgraph/ng_message.h> #include <netgraph/ng_message.h>
@ -261,7 +262,7 @@ union uniq {
#define LEAVE(x) do { error = x; goto quit; } while(0) #define LEAVE(x) do { error = x; goto quit; } while(0)
static void pppoe_start(sessp sp); static void pppoe_start(sessp sp);
static void sendpacket(sessp sp); static void ng_pppoe_sendpacket(sessp sp);
static void pppoe_ticker(node_p node, hook_p hook, void *arg1, int arg2); static void pppoe_ticker(node_p node, hook_p hook, void *arg1, int arg2);
static const struct pppoe_tag *scan_tags(sessp sp, static const struct pppoe_tag *scan_tags(sessp sp,
const struct pppoe_hdr* ph); const struct pppoe_hdr* ph);
@ -383,7 +384,8 @@ insert_tag(sessp sp, const struct pppoe_tag *tp)
if ((i = neg->numtags++) < NUMTAGS) { if ((i = neg->numtags++) < NUMTAGS) {
neg->tags[i] = tp; neg->tags[i] = tp;
} else { } else {
printf("pppoe: asked to add too many tags to packet\n"); log(LOG_NOTICE, "ng_pppoe: asked to add too many tags to "
"packet\n");
neg->numtags--; neg->numtags--;
} }
} }
@ -406,7 +408,7 @@ make_packet(sessp sp) {
uint16_t length = 0; uint16_t length = 0;
KASSERT((sp->neg != NULL) && (sp->neg->m != NULL), KASSERT((sp->neg != NULL) && (sp->neg->m != NULL),
("%s: make_packet called from wrong state", __func__)); ("%s: called from wrong state", __func__));
CTR2(KTR_NET, "%20s: called %d", __func__, sp->Session_ID); CTR2(KTR_NET, "%20s: called %d", __func__, sp->Session_ID);
dp = (char *)wh->ph.tag; dp = (char *)wh->ph.tag;
@ -415,7 +417,7 @@ make_packet(sessp sp) {
tag++, count++) { tag++, count++) {
tlen = ntohs((*tag)->tag_len) + sizeof(**tag); tlen = ntohs((*tag)->tag_len) + sizeof(**tag);
if ((length + tlen) > (ETHER_MAX_LEN - 4 - sizeof(*wh))) { if ((length + tlen) > (ETHER_MAX_LEN - 4 - sizeof(*wh))) {
printf("pppoe: tags too long\n"); log(LOG_NOTICE, "ng_pppoe: tags too long\n");
sp->neg->numtags = count; sp->neg->numtags = count;
break; /* XXX chop off what's too long */ break; /* XXX chop off what's too long */
} }
@ -714,18 +716,21 @@ ng_pppoe_rcvmsg(node_p node, item_p item, hook_p lasthook)
case NGM_PPPOE_SERVICE: case NGM_PPPOE_SERVICE:
ourmsg = (struct ngpppoe_init_data *)msg->data; ourmsg = (struct ngpppoe_init_data *)msg->data;
if (msg->header.arglen < sizeof(*ourmsg)) { if (msg->header.arglen < sizeof(*ourmsg)) {
printf("pppoe: init data too small\n"); log(LOG_ERR, "ng_pppoe[%x]: init data too "
"small\n", node->nd_ID);
LEAVE(EMSGSIZE); LEAVE(EMSGSIZE);
} }
if (msg->header.arglen - sizeof(*ourmsg) > if (msg->header.arglen - sizeof(*ourmsg) >
PPPOE_SERVICE_NAME_SIZE) { PPPOE_SERVICE_NAME_SIZE) {
printf("pppoe_rcvmsg: service name too big"); log(LOG_ERR, "ng_pppoe[%x]: service name "
"too big\n", node->nd_ID);
LEAVE(EMSGSIZE); LEAVE(EMSGSIZE);
} }
if (msg->header.arglen - sizeof(*ourmsg) < if (msg->header.arglen - sizeof(*ourmsg) <
ourmsg->data_len) { ourmsg->data_len) {
printf("pppoe: init data has bad length," log(LOG_ERR, "ng_pppoe[%x]: init data has bad "
" %d should be %zd\n", ourmsg->data_len, "length, %d should be %zd\n", node->nd_ID,
ourmsg->data_len,
msg->header.arglen - sizeof (*ourmsg)); msg->header.arglen - sizeof (*ourmsg));
LEAVE(EMSGSIZE); LEAVE(EMSGSIZE);
} }
@ -767,7 +772,8 @@ ng_pppoe_rcvmsg(node_p node, item_p item, hook_p lasthook)
break; break;
if (sp->state != PPPOE_SNONE) { if (sp->state != PPPOE_SNONE) {
printf("pppoe: Session already active\n"); log(LOG_NOTICE, "ng_pppoe[%x]: Session already "
"active\n", node->nd_ID);
LEAVE(EISCONN); LEAVE(EISCONN);
} }
@ -882,7 +888,8 @@ ng_pppoe_rcvmsg(node_p node, item_p item, hook_p lasthook)
* If you do it twice you just overwrite. * If you do it twice you just overwrite.
*/ */
if (sp->state != PPPOE_PRIMED) { if (sp->state != PPPOE_PRIMED) {
printf("pppoe: Session not primed\n"); log(LOG_NOTICE, "ng_pppoe[%x]: session not "
"primed\n", node->nd_ID);
LEAVE(EISCONN); LEAVE(EISCONN);
} }
neg = sp->neg; neg = sp->neg;
@ -1012,7 +1019,7 @@ pppoe_start(sessp sp)
insert_tag(sp, &uniqtag.hdr); insert_tag(sp, &uniqtag.hdr);
insert_tag(sp, &sp->neg->service.hdr); insert_tag(sp, &sp->neg->service.hdr);
make_packet(sp); make_packet(sp);
sendpacket(sp); ng_pppoe_sendpacket(sp);
} }
static int static int
@ -1105,7 +1112,8 @@ ng_pppoe_rcvdata(hook_p hook, item_p item)
if( m->m_len < sizeof(*wh)) { if( m->m_len < sizeof(*wh)) {
m = m_pullup(m, sizeof(*wh)); /* Checks length */ m = m_pullup(m, sizeof(*wh)); /* Checks length */
if (m == NULL) { if (m == NULL) {
printf("couldn't m_pullup\n"); log(LOG_NOTICE, "ng_pppoe[%x]: couldn't "
"m_pullup(wh)\n", node->nd_ID);
LEAVE(ENOBUFS); LEAVE(ENOBUFS);
} }
} }
@ -1124,7 +1132,10 @@ ng_pppoe_rcvdata(hook_p hook, item_p item)
if( m->m_len < m->m_pkthdr.len) { if( m->m_len < m->m_pkthdr.len) {
m = m_pullup(m, m->m_pkthdr.len); m = m_pullup(m, m->m_pkthdr.len);
if (m == NULL) { if (m == NULL) {
printf("couldn't m_pullup\n"); log(LOG_NOTICE, "ng_pppoe[%x]: "
"couldn't "
"m_pullup(pkthdr)\n",
node->nd_ID);
LEAVE(ENOBUFS); LEAVE(ENOBUFS);
} }
} }
@ -1147,7 +1158,8 @@ ng_pppoe_rcvdata(hook_p hook, item_p item)
} }
} }
if (m == NULL) { if (m == NULL) {
printf("packet fragmented\n"); log(LOG_NOTICE, "ng_pppoe[%x]: packet "
"fragmented\n", node->nd_ID);
LEAVE(EMSGSIZE); LEAVE(EMSGSIZE);
} }
} }
@ -1204,13 +1216,15 @@ ng_pppoe_rcvdata(hook_p hook, item_p item)
utag = get_tag(ph, PTT_HOST_UNIQ); utag = get_tag(ph, PTT_HOST_UNIQ);
if ((utag == NULL) if ((utag == NULL)
|| (ntohs(utag->tag_len) != sizeof(sp))) { || (ntohs(utag->tag_len) != sizeof(sp))) {
printf("no host unique field\n"); log(LOG_NOTICE, "ng_pppoe[%x]: no host "
"unique field\n", node->nd_ID);
LEAVE(ENETUNREACH); LEAVE(ENETUNREACH);
} }
sendhook = pppoe_finduniq(node, utag); sendhook = pppoe_finduniq(node, utag);
if (sendhook == NULL) { if (sendhook == NULL) {
printf("no matching session\n"); log(LOG_NOTICE, "ng_pppoe[%x]: no "
"matching session\n", node->nd_ID);
LEAVE(ENETUNREACH); LEAVE(ENETUNREACH);
} }
@ -1220,7 +1234,8 @@ ng_pppoe_rcvdata(hook_p hook, item_p item)
*/ */
sp = NG_HOOK_PRIVATE(sendhook); sp = NG_HOOK_PRIVATE(sendhook);
if (sp->state != PPPOE_SINIT) { if (sp->state != PPPOE_SINIT) {
printf("session in wrong state\n"); log(LOG_NOTICE, "ng_pppoe[%x]: session "
"in wrong state\n", node->nd_ID);
LEAVE(ENETUNREACH); LEAVE(ENETUNREACH);
} }
neg = sp->neg; neg = sp->neg;
@ -1249,7 +1264,7 @@ ng_pppoe_rcvdata(hook_p hook, item_p item)
scan_tags(sp, ph); scan_tags(sp, ph);
make_packet(sp); make_packet(sp);
sp->state = PPPOE_SREQ; sp->state = PPPOE_SREQ;
sendpacket(sp); ng_pppoe_sendpacket(sp);
break; break;
case PADR_CODE: case PADR_CODE:
@ -1311,7 +1326,7 @@ ng_pppoe_rcvdata(hook_p hook, item_p item)
scan_tags(sp, ph); scan_tags(sp, ph);
make_packet(sp); make_packet(sp);
sp->state = PPPOE_NEWCONNECTED; sp->state = PPPOE_NEWCONNECTED;
sendpacket(sp); ng_pppoe_sendpacket(sp);
/* /*
* Having sent the last Negotiation header, * Having sent the last Negotiation header,
* Set up the stored packet header to * Set up the stored packet header to
@ -1560,7 +1575,7 @@ ng_pppoe_rcvdata(hook_p hook, item_p item)
insert_tag(sp, &uniqtag.hdr); insert_tag(sp, &uniqtag.hdr);
scan_tags(sp, ph); scan_tags(sp, ph);
make_packet(sp); make_packet(sp);
sendpacket(sp); ng_pppoe_sendpacket(sp);
break; break;
/* /*
@ -1655,8 +1670,9 @@ ng_pppoe_disconnect(hook_p hook)
/* Generate a packet of that type. */ /* Generate a packet of that type. */
MGETHDR(m, M_DONTWAIT, MT_DATA); MGETHDR(m, M_DONTWAIT, MT_DATA);
if(m == NULL) if (m == NULL)
printf("pppoe: Session out of mbufs\n"); log(LOG_NOTICE, "ng_pppoe[%x]: session out of "
"mbufs\n", node->nd_ID);
else { else {
m->m_pkthdr.rcvif = NULL; m->m_pkthdr.rcvif = NULL;
m->m_pkthdr.len = m->m_len = sizeof(*wh); m->m_pkthdr.len = m->m_len = sizeof(*wh);
@ -1749,13 +1765,14 @@ pppoe_ticker(node_p node, hook_p hook, void *arg1, int arg2)
break; break;
default: default:
/* Timeouts have no meaning in other states. */ /* Timeouts have no meaning in other states. */
printf("pppoe: unexpected timeout\n"); log(LOG_NOTICE, "ng_pppoe[%x]: unexpected timeout\n",
node->nd_ID);
} }
} }
static void static void
sendpacket(sessp sp) ng_pppoe_sendpacket(sessp sp)
{ {
struct mbuf *m0 = NULL; struct mbuf *m0 = NULL;
hook_p hook = sp->hook; hook_p hook = sp->hook;
@ -1770,7 +1787,8 @@ sendpacket(sessp sp)
case PPPOE_DEAD: case PPPOE_DEAD:
case PPPOE_SNONE: case PPPOE_SNONE:
case PPPOE_CONNECTED: case PPPOE_CONNECTED:
printf("pppoe: sendpacket: unexpected state\n"); log(LOG_NOTICE, "%s: unexpected state %d\n",
__func__, sp->state);
break; break;
case PPPOE_NEWCONNECTED: case PPPOE_NEWCONNECTED:
@ -1807,7 +1825,7 @@ sendpacket(sessp sp)
default: default:
error = EINVAL; error = EINVAL;
printf("pppoe: timeout: bad state\n"); log(LOG_NOTICE, "%s: bad state %d\n", __func__, sp->state);
} }
} }