Re: setsockopt - SO_REUSEADDR

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi...
On Wed, Jul 26, 2006 at 12:36:29PM +0530, Chinmaya Mishra wrote:
> Hi all,
> 
> I am creating a socket in kernel. It is able to bind. But after abnormal
> termination of the module, I am not able to bind the socket once again. 
> Here i use
> 
> .......................................................................
> /* create a socket */
> if ((err = sock_create(AF_INET, SOCK_DGRAM, IPPROTO_UDP, &sock)) < 0) {
>    printk(KERN_INFO MODULE_NAME": Could not create a datagram socket, 
> error = %d\n", -ENXIO);
>    return;
> }
> 
> if((err = sock->ops->setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, 
> (void*)&option, sizeof(option)))<0)
>             printk(KERN_INFO MODULE_NAME": Error in set socket opt for 
> SO_REUSEADDR \n");

Either use:
    /* must use SOL_IP because we are directly calling proto impl. */
    sock->ops->setsockopt(sock, SOL_IP, ...);
    
or:
    /* use "generic" setsockopt entry point */
    sock_setsockopt(sock, SOL_SOCKET, ...);
    
or directly ride the horse:
    sock->sk->sk_reuse=1;

BTW don't forget to wrap all "syscall-like" calling with else you'll
get EFAULTs:

    mm_segment_t oldfs;
    set_fs(KERNEL_DS);
    :
    /* syscall'ing-alike ...*/
    :
    set_fs(oldfs);

Regards... and be kind to feedback your results
-- 
--Juanjo

#  Juan Jose Ciarlante (JuanJo) jjo ;at; mendoza.gov.ar                     #
#  GnuPG Public Key: gpg --keyserver wwwkeys.eu.pgp.net --recv-key 66727177 #
#   Key fingerprint: 0D2F 3E5D 8B5C 729E 0560  F453 A3F7 E249 6672 7177     #

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux